#include<stdio.h>
#include<conio.h>
#include<process.h>
void create();
void display();
void addbeg();
void addlast();
struct node
{
int info;
struct node *link;
}*start=NULL;
void main()
{
int n;
clrscr();
while(1)
{
printf("\n **menu**\n");
printf("\n 1. to create list \n 2. to display list");
printf("\n 3. to add node at beginning of linked list");
printf("\n 4. to add node at the last of linked list");
printf("\n 5. exit");
printf("\n Enter your choice:-");
scanf("%d",&n);
switch(n)
{
case 1 : create();
break;
case 2 : display();
break;
case 3 : addbeg();
break;
case 4 : addlast();
break;
case 5 : exit(0);
}
}
getch();
}
void create()
{
struct node *temp,*q;
int x;
temp=(struct node *)malloc(sizeof(struct node));
if(temp==NULL)
{
printf("\n Insufficient memory");
}
else
{
printf("\n Enter number:-");
scanf("%d",&x);
temp->info=x;
temp->link=NULL;
if(start==NULL)
{
start=temp;
}
else
{
q=start;
while(q->link!=start)
{
q=q->link;
}
q->link=temp;
}
temp->link=start;
}
}
void display()
{
struct node *q;
printf("\n Circular linked list is:-\n\n");
q=start;
while(q->link!=start)
{
printf(" %d",q->info);
q=q->link;
}
printf(" %d",q->info);
}
void addbeg()
{
int x;
struct node *temp,*q;
temp=(struct node*)malloc(sizeof(struct node));
if(temp==NULL)
{
printf("\n Insufficient memory");
}
else
{
printf("\n Enter number:-");
scanf("%d",&x);
temp->info=x;
temp->link=NULL;
q=start;
while(q->link!=start)
{
q=q->link;
}
temp->link=start;
start=temp;
q->link=start;
}
}
void addlast()
{
struct node *temp,*q;
int x;
temp=(struct node*)malloc(sizeof(struct node));
if(temp==NULL)
{
printf("\n Insufficient memory");
}
else
{
printf("\n Enter number:-");
scanf("%d",&x);
temp->info=x;
temp->link=NULL;
q=start;
while(q->link!=start)
{
q=q->link;
}
q->link=temp;
temp->link=start;
}
}
#include<conio.h>
#include<process.h>
void create();
void display();
void addbeg();
void addlast();
struct node
{
int info;
struct node *link;
}*start=NULL;
void main()
{
int n;
clrscr();
while(1)
{
printf("\n **menu**\n");
printf("\n 1. to create list \n 2. to display list");
printf("\n 3. to add node at beginning of linked list");
printf("\n 4. to add node at the last of linked list");
printf("\n 5. exit");
printf("\n Enter your choice:-");
scanf("%d",&n);
switch(n)
{
case 1 : create();
break;
case 2 : display();
break;
case 3 : addbeg();
break;
case 4 : addlast();
break;
case 5 : exit(0);
}
}
getch();
}
void create()
{
struct node *temp,*q;
int x;
temp=(struct node *)malloc(sizeof(struct node));
if(temp==NULL)
{
printf("\n Insufficient memory");
}
else
{
printf("\n Enter number:-");
scanf("%d",&x);
temp->info=x;
temp->link=NULL;
if(start==NULL)
{
start=temp;
}
else
{
q=start;
while(q->link!=start)
{
q=q->link;
}
q->link=temp;
}
temp->link=start;
}
}
void display()
{
struct node *q;
printf("\n Circular linked list is:-\n\n");
q=start;
while(q->link!=start)
{
printf(" %d",q->info);
q=q->link;
}
printf(" %d",q->info);
}
void addbeg()
{
int x;
struct node *temp,*q;
temp=(struct node*)malloc(sizeof(struct node));
if(temp==NULL)
{
printf("\n Insufficient memory");
}
else
{
printf("\n Enter number:-");
scanf("%d",&x);
temp->info=x;
temp->link=NULL;
q=start;
while(q->link!=start)
{
q=q->link;
}
temp->link=start;
start=temp;
q->link=start;
}
}
void addlast()
{
struct node *temp,*q;
int x;
temp=(struct node*)malloc(sizeof(struct node));
if(temp==NULL)
{
printf("\n Insufficient memory");
}
else
{
printf("\n Enter number:-");
scanf("%d",&x);
temp->info=x;
temp->link=NULL;
q=start;
while(q->link!=start)
{
q=q->link;
}
q->link=temp;
temp->link=start;
}
}