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