You are on page 1of 3

Date : 7-10-15

Roll no.: 17919


Program of circular linked listinsertion of element
at the beginning.
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct node
{
int info;
struct node *link;
};
struct node *first;
void main()
{
void create();
void insert_beg();
void traverse();
clrscr();
create();
insert_beg();
traverse();
getch();
}
void create()
{
struct node *ptr,*cpt;
char ch;
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;
}
void insert_beg()
{
struct node *ptr,*cpt;
ptr=(struct node*)malloc(sizeof(struct node));
printf("input the information of the node to be inserted");
scanf("%d",&ptr->info);
cpt=first;
while(cpt->link!=first)
{
cpt=cpt->link;
}
ptr->link=first;
first=ptr;
cpt->link=first;
}
void traverse()
{ struct node *ptr;
printf("traversing of link is \n\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