58)Write a menu driven program in C for implementation of circular linked list. -Create -Display -Add node at beginning -Add node at last – Exit


#include<stdio.h>
#include<conio.h>
struct node
{
int data;
struct node *link;
}*start;
void addlast(int);
void create(int);
void disp();
void addbeg(int);
void main()
{
int ch,n,i,m,a,pos;
clrscr();
start=NULL;
do
{
printf(“\n\nMENU\n\n”);
printf(“\n1.CREATE\n”);
printf(“\n2.DISPLAY\n”);
printf(“\n3.ADDBEG\n”);
printf(“\n4.ADDLAST \n”);
printf(“\n5.EXIT\n”);
printf(“\nENTER UR CHOICE\n”);
scanf(“%d”,&ch);
switch(ch)
{
case 1:
printf(“\n\nHOW MANY NODES U WANT TO CREATE\n”);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
printf(“\nENTER THE DATA”);
scanf(“%d”,&m);
create(m);
}
break;
case 2:
disp();
break;
case 5:
exit(0);
case 3:

printf(“\nENTER THE VALUE FOR NODE”);
scanf(“%d”,&a);
addbeg(a);
break;
case 4:
printf(“\nENTER THE VALUE FOR NODE\n”);
scanf(“%d”,&m);
addlast(m);
break;
}
}
while(ch!=5);
getch();
}
void create(int data)
{
struct node *q,*tmp;
tmp=(struct node *)malloc(sizeof(struct node));
tmp->data=data;
tmp->link=NULL;
if(start==NULL)
{
start=tmp;
}
else
{
q=start;
while(q->link!=NULL)
q=q->link;
q->link=tmp;
}
}
void disp()
{
struct node *q;
if(start==NULL)
{
printf(“\n\nLIST IS EMPTY”);
}
else
{
q=start;
while(q!=NULL)
{
printf(“%d->”,q->data);
q=q->link;
}
printf(“NULL”);
}
}
void addbeg(int data)
{
struct node *tmp;
tmp=(struct node *)malloc(sizeof(struct node ));
tmp->data=data;
tmp->link=start;
start=tmp;
}
void addlast(int data)
{
struct node *q,*tmp;
tmp=(struct node *) malloc(sizeof(struct node));
tmp->data=data;
tmp->link=NULL;
q=start;
while(q->link!=NULL)
q=q->link;
q->link=tmp;
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s