#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
int data;
struct node *link;
}
NODE;
NODE * get_node()
{
NODE *p;
p = (NODE*)malloc(sizeof(NODE));
printf("Enter data:");
scanf("%d",&p->data);
p->link = NULL;
return p;
}
NODE * create_csll()
{
int n,i;
NODE *first,*last,*q;
printf("Enter no.of nodes:");
scanf("%d",&n);
first = last = NULL;
for(i=1;i<=n;i++)
{
q = get_node();
if(first==NULL)
{
first = q;
first->link = first;
}
else
{
last->link = q;
q->link = first;
}
last = q;
}
return first;
}
void display(NODE *h)
{
NODE *p;
p = h;
while(1)
{
printf("%4d",p->data);
p=p->link;
if(p==h) break;
}
printf("\n");
}
void main()
{
NODE *start=NULL;
start = create_csll();
display(start);
getch();
}
Output:
1.Insert
2.Delete
3.Display
4.Exit
Enter your choice (1-4): 1
Enter data: 2
1.Insert
2.Delete
3.Display
4.Exit
Enter your choice (1-4): 3
2
1.Insert
2.Delete
3.Display
4.Exit
Enter your choice (1-4): 2
Deleted data: 2
1.Insert
2.Delete
3.Display
4.Exit
Enter your choice (1-4): 4
/