0% found this document useful (0 votes)
42 views3 pages

Circular List: Delete First Node

The document describes a program to delete nodes from the beginning of a circular linked list in C. It includes functions to create the list by inputting node data, delete the first node by changing the first pointer and freeing the memory, and traverse the list by printing each node's data and link. The main function calls the create, delete, and traverse functions to build the list, remove the first node, and display the resulting list.

Uploaded by

Sanjeev
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views3 pages

Circular List: Delete First Node

The document describes a program to delete nodes from the beginning of a circular linked list in C. It includes functions to create the list by inputting node data, delete the first node by changing the first pointer and freeing the memory, and traverse the list by printing each node's data and link. The main function calls the create, delete, and traverse functions to build the list, remove the first node, and display the resulting list.

Uploaded by

Sanjeev
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Date: 7-10-15

Roll no.: 17919

Program of circular linked list deletion from the


beginnning.
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct node
{
int info;
struct node *link;
};
struct node *first;
void main()
{
void create();
voiddelete_beg();
void traverse();
clrscr();
create();
delete_beg();
traverse();
getch();
}
void create()
{
struct node *ptr,*cpt;
charch;
ptr=(struct node*)malloc(sizeof(struct node));
printf("input first node information");
scanf("%d",&ptr->info);
first=ptr;
do
{
cpt=(struct node*)malloc(sizeof(struct node));
printf("input next node information");
scanf("%d",&cpt->info);

ptr->link=cpt;
ptr=cpt;
printf("press<Y/N> for more node\n");
ch=getch();
}while(ch=='y');
ptr->link=first;
}
voiddelete_beg()
{
struct node *ptr,*cpt;
cpt=first;
while(cpt->link!=first)
cpt=cpt->link;
ptr=first;
first=ptr->link;
cpt->link=first;
free(ptr);
}
void traverse()
{ struct node *ptr;
printf("traversing if link is \n");
ptr=first;
while(ptr->link!=first)
{
printf(" %d->%d",ptr->info,ptr->link);
ptr=ptr->link;
}
printf(" %d->%d",ptr->info,ptr->link);
}

Date: 7-10-15
Roll no.: 17919

Output

You might also like