forked from santoshvijapure/DS_with_hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Circular_linked_list.c
79 lines (76 loc) · 1.07 KB
/
Circular_linked_list.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node*link;
}*start=NULL,*last=NULL,*temp=NULL;
void creation(int item)
{
struct node*p;
p=(struct node*)malloc(sizeof(struct node));
p->data=item;
p->link=NULL;
last=p;
if(start==NULL)
{
start=p;
last=p;
}
else
{
temp=start;
while(temp->link!=NULL)
{
temp=temp->link;
}
temp->link=p;
last=p;
last->link=start;
}
last->link=start;
}
void display()
{
if(start==NULL)
{
printf("List is empty");
return;
}
else
{
temp=start;
while(temp->link!=NULL)
{
printf("%d\n",temp->data);
temp=temp->link;
}
printf("%d\n",temp->data);
}
}
int main()
{
int item,i,n,selection,position;
label:
printf("Enter 1 to create");
printf("\nEnter 2 to display");
printf("\nyour selection");
scanf("%d",&selection);
if(selection==1)
{
printf("Enter no. of nodes");
scanf("%d",&n);
printf("Enter numbers\n");
for(i=0;i<n;i++)
{
scanf("%d",&item);
creation(item);
}
goto label;
}
else if(selection==2)
{
display();
goto label;
}
}