-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathdoublyylinkedlist.c
More file actions
187 lines (182 loc) Β· 4.92 KB
/
Copy pathdoublyylinkedlist.c
File metadata and controls
187 lines (182 loc) Β· 4.92 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#include <stdio.h>
#include<conio.h>
struct student
{
int roll;
char name[40];
struct student *n,*p;
} stud;
int main()
{
struct student *s, *c, *t,*last;
int ch, tr;
s = c = t = '\0';
do
{
printf("linked list operations\n");
printf("1.add record\n");
printf("2.insert record\n");
printf("3.delete record\n");
printf("4.search record\n");
printf("5.display\n");
printf("6.exit\n");
printf("enter your choice\n");
scanf("%d", &ch);
switch (ch)
{
case 1:
printf("add record\n");
t = (stud*)malloc(sizeof(stud));
printf("enter name\n");
scanf("%s", t->name);
printf("enter roll\n");
scanf("%s", &t->roll);
t->n = '\0';
t->p = '\0';
if (s=='\0')
s = t;
else
{
c = s;
while (c->n != '\0')
{
c = c->n;
}
c->n = t;
t->p=c;
}
printf("record added\n");
break;
case 2:
printf("insert record\n");
printf("enter the roll at which record has to be inserted\n");
scanf("%d", &tr);
t = (stud*)malloc(sizeof(stud));
printf("enter name\n");
scanf("%s", t->name);
printf("enter roll\n");
scanf("%s", &t->roll);
t->n = '\0';
t->p = '\0';
if (s == '\0')
printf("no record found");
else
{
if (s->roll == tr)
{
t->n = s;
s->p=t;
s = t;
printf("record inserted\n")
}
c = s;
else
{
while (c->n != '\0')
{
if (c->n->roll == tr)
{
t->n = c->n;
c->n->p=t;
c->n = t;
t->p=c;
printf("record inserted\n");
break;
}
else
{
c = c->n;
}
}
if (c->n == '\0')
printf("record not found");
}
}
break;
case 3:
printf("deletion\n");
if (s == '\0')
printf("no record found\n");
printf("enter the roll number for which details has to be deleted\n");
scanf("%d", &tr);
if (s->roll == tr)
{
t = s;
s = t->n;
s->p='\0';
free(t);
}
else
{
c = s;
while (c->n !== '\0')
{
if (c->n->roll = tr)
{
t = c->n;
c->n = t->n;
c->n->p=c;
free(t);
if(c->n=='\0')
t==c;
break;
/* code */
}
else
{
c=c->n;
}
}
}
break;
else printf("cant be deleted\n");
case 4:
if (s == '\0')
printf("record not found\n");
else
{
printf("enter the roll number to be searched\n");
scanf("%d", &tr);
c = s;
while (c != '\0')
{
if (c->roll == tr)
{
printf("record found\n");
printf("roll=%d\nname=%s", c->roll, c->name);
break;
}
c = c->n;
}
if (c == '\0')
{
printf("roll doesnot exist\n");
}
}
break;
case 5:
if (s = '\0')
{
printf("no record exist\n");
}
else
{
c = s;
while (c != '\0')
{
printf("roll=%d", c->roll);
printf("name=%s", c->name);
printf("\n");
c = c->n;
}
}
break;
case 6:
continue;
default:
printf("invalid choice\n");
}
/* code */
} while (ch != 6);
return 0;
}