-
Notifications
You must be signed in to change notification settings - Fork 0
/
circularLL.c
73 lines (68 loc) · 1.25 KB
/
circularLL.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
#include<stdio.h>
#include<stdlib.h>
struct CLL
{
int data;
struct CLL *next;
}*first;
void create(int x)
{
struct CLL *p;
struct CLL *temp;
temp=(struct CLL*)malloc(sizeof(struct CLL));
scanf("%d",&temp->data );
temp->next=NULL;
first=temp;
for(int i=1;i<=x-1;i++)
{
p=(struct CLL*)malloc(sizeof(struct CLL));
scanf("%d",&p->data);
p->next=first;
temp->next=p;
temp=p;
}
}
void display(struct CLL *p)
{
do{
printf ("%d\t",p->data);
p=p->next;
}while(p!=first);
}
void insertBegin(int y)
{
struct CLL *p,*temp=first;
while(temp->next!=first)
temp=temp->next;
p=(struct CLL*)malloc(sizeof(struct CLL));
temp->next=p;
p->data=y;
p->next=first;
first=p;
}
void deleteBegin(struct CLL *p)
{
struct CLL *temp;
while(temp->next!=first)
temp=temp->next;
p=p->next;
temp->next=p;
free(first);
first=p;
}
int main ()
{
printf ("Enter the number of data to be feed\n ");
int x,y,z;
scanf("%d",&x);
create (x);
display(first);
printf("\n");
scanf("%d",&y);
insertBegin(y);
display(first);
deleteBegin(first);
printf("\n The first element is deleted from the circular linked list : ");
display(first);
return 0;
}