-
Notifications
You must be signed in to change notification settings - Fork 0
/
LL8_operations_on_circular_LL.c
122 lines (101 loc) · 2 KB
/
LL8_operations_on_circular_LL.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <stdio.h>
#include<stdlib.h>
struct node{
int info;
struct node*next;
};
struct node*getnode(){
struct node*p;
p=(struct node*)malloc(sizeof(struct node));
return p;
}
void insbeg(struct node**cstart,int x){
struct node*p;
p=getnode();
p->info=x;
if((*cstart)!=NULL){
p->next=(*cstart)->next;
(*cstart)->next=p;
}
else{
*cstart=p;
(*cstart)->next=p;
}
}
void insend(struct node**cstart,int x){
struct node*p;
p=getnode();
p->info=x;
if((*cstart)!=NULL){
p->next=(*cstart)->next;
(*cstart)->next=p;
*cstart=p;
}
else{
*cstart=p;
(*cstart)->next=p;
}
}
void insafter(struct node**q,int x){
struct node*p;
if(q==NULL){
printf("void insertion");
}
else{
p=getnode();
p->info=x;
p->next=(*q)->next;
(*q)->next=p;
}
}
int delbeg(struct node**cstart){
struct node*p;
p=(*cstart)->next;
(*cstart)->next=p->next;
if((*cstart)->next==(*cstart)){
*cstart=NULL;
}
int x=p->info;
free(p);
return x;
}
int delend(struct node**cstart){
struct node*p,*q;
q=*cstart;
p=(*cstart)->next;
while(p!=*cstart){
p=p->next;
}
p->next=(*cstart)->next;
*cstart=p;
int x=q->info;
free(q);
return x;
}
int delafter(struct node**q){
struct node*p;
p=(*q)->next;
(*q)->next=p->next;
int x=p->info;
free(p);
return x;
}
void traverse(struct node*cstart){
struct node*p;
p=cstart->next;
while(p!=cstart){
printf("%d ",p->info);
p=p->next;
}
printf("%d ",p->info);
}
int main()
{
struct node*cstart;
cstart=NULL;
insbeg(&cstart,10);
insbeg(&cstart,20);
insbeg(&cstart,30);
traverse(cstart);
return 0;
}