-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDLLMENU.C
More file actions
324 lines (319 loc) · 8.21 KB
/
DLLMENU.C
File metadata and controls
324 lines (319 loc) · 8.21 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
#include<windows.h>
#include<dos.h>
struct node
{
int roll_num;
char name[20];
struct node *next;
struct node *prev;
}*start;
void create_list(int rn,char a[])
{
struct node *node,*new_node;
new_node=(struct node *)malloc(sizeof(struct node));
new_node->roll_num=rn;
strcpy(new_node->name,a);
new_node->next=NULL;
new_node->prev=NULL;
if(start==NULL)
start=new_node;
else
{
node=start;
while(node->next!=NULL)
node=node->next;
node->next=new_node;
new_node->prev = node;
}
}
void displayfor()
{
struct node *node;
if(start==NULL)
{
printf("\n List is empty ");
return;
}
node=start;
printf("\n List is: ");
while(node!=NULL)
{
printf("\n Roll number: %d",node->roll_num);
printf("\n Name: %s",node->name);
node=node->next;
}
}
void displayback()
{
struct node *node;
if(start==NULL)
{
printf("\n List is empty ");
return;
}
node=start;
printf("\n List is: ");
while(node->next!=NULL)
node=node->next;
while(node!=NULL)
{
printf("\n Roll number: %d",node->roll_num);
printf("\n Name: %s",node->name);
node=node->prev;
}
}
void addtobeg(int rn,char a[])
{
struct node *new_node;
struct node *node=start;
new_node=(struct node *)malloc(sizeof(struct node));
new_node->roll_num=rn;
strcpy(new_node->name,a);
new_node->next=start;
new_node->prev=NULL;
node->prev=new_node;
start=new_node;
}
void addtoend(int rn,char a[])
{
struct node *node=start;
struct node *new_node;
new_node=(struct node *)malloc(sizeof(struct node));
new_node->roll_num=rn;
strcpy(new_node->name,a);
while(node->next!=NULL)
node=node->next;
node->next=new_node;
new_node->prev=node;
new_node->next=NULL;
}
void addtopos(int rn,char a[],int pos)
{
struct node *node=start;
int c;
struct node *new_node;
new_node=(struct node *)malloc(sizeof(struct node));
new_node->roll_num=rn;
strcpy(new_node->name,a);
for(c=1; c<pos-1; c++)
{
if(node->next!=NULL)
{
node=node->next;
}
}
new_node->next=node->next;
node->next->prev=new_node;
node->next=new_node;
new_node->prev=node;
}
void count()
{
struct node *node=start;
int cnt=0;
while(node!=NULL)
{
node=node->next;
cnt++;
}
printf("\n No. of elements are %d ",cnt);
}
void delfrombeg()
{
struct node *node=start;
if(node==NULL)
{
printf("\n Underflow error ");
return;
}
start=node->next;
start->prev=NULL;
return;
}
void delfromend()
{
struct node *node=start;
if(node==NULL)
{
printf("\n Underflow error ");
return;
}
while(node->next->next!=NULL)
node=node->next;
node->next=NULL;
}
void delfrompos(int node_no)
{
struct node *node=start;
int c=1;
if(node==NULL)
{
printf("\n Underflow error ");
return;
}
while(c<node_no-1)
{
node=node->next;
c++;
}
node->next=node->next->next;
node->next->next->prev=node;
}
int main()
{
int ch1,ch2,ch3,ch,n,rn,ptr,i,pos;
char a[20];
start=NULL;
do
{
system("cls");
printf("\n 1: Create text ");
printf("\n 2: Insertion ");
printf("\n 3: Display ");
printf("\n 4: Count ");
printf("\n 5: Deletion ");
printf("\n 6: Quit ");
printf("\n Enter choice ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\n Enter no. of records ");
scanf("%d",&n);
for(i=0; i<n; i++)
{
printf("\n Enter Roll number ");
scanf("%d",&rn);
printf("\n Enter Name ");
scanf("%s",&a);
create_list(rn,a);
}
printf("\n Kushdeep Singh ");
Sleep(4000); break;
case 2:
do
{
printf("\n 1: Insertion at beginning ");
printf("\n 2: Insertion at end ");
printf("\n 3: Insertion at specified location ");
printf("\n 4: Return ");
printf("\n Enter choice ");
scanf("%d",&ch1);
switch(ch1)
{
case 1:
printf("\n Enter the record to be insert ");
printf("\n Enter Roll number ");
scanf("%d",&rn);
printf("\n Enter Name ");
scanf("%s",&a);
addtobeg(rn,a);
displayfor();
printf("\n Kushdeep Singh ");
Sleep(1000); break;
case 2:
printf("\n Enter the record to be insert ");
printf("\n Enter Roll number ");
scanf("%d",&rn);
printf("\n Enter Name ");
scanf("%s",&a);
addtoend(rn,a);
displayfor();
printf("\n Kushdeep Singh ");
Sleep(1000); break;
case 3:
printf("\n Enter the record to be insert ");
printf("\n Enter Roll number ");
scanf("%d",&rn);
printf("\n Enter Name ");
scanf("%s",&a);
printf("\n Enter the position ");
scanf("%d",&pos);
addtopos(rn,a,pos);
displayfor();
printf("\n Kushdeep Singh ");
Sleep(1000); break;
case 4:
break;
default:
printf("\n Wrong Choice ");
}
}
while(ch1!=4);
Sleep(4000); break;
case 3:
do
{
printf("\n 1: Display from forward ");
printf("\n 2: Display from backward ");
printf("\n 3: Return ");
printf("\n Enter choice ");
scanf("%d",&ch2);
switch(ch2)
{
case 1:
displayfor();
printf("\n Kushdeep Singh ");
Sleep(1000); break;
case 2:
displayback();
printf("\n Kushdeep Singh ");
Sleep(1000); break;
case 3:
break;
default:
printf("\n Wrong Choice ");
}
}
while(ch2!=3);
Sleep(4000); break;
case 4:
count();
Sleep(4000); break;
case 5:
do
{
printf("\n 1: Deletion from beginning ");
printf("\n 2: Deletion from end ");
printf("\n 3: Deletion specified location ");
printf("\n 4: Return ");
printf("\n Enter choice ");
scanf("%d",&ch3);
switch(ch3)
{
case 1:
delfrombeg();
displayfor();
printf("\n Kushdeep Singh ");
Sleep(1000); break;
case 2:
delfromend();
displayfor();
printf("\n Kushdeep Singh ");
Sleep(1000); break;
case 3:
printf("\n Enter the record number to delete ");
scanf("%d",&pos);
delfrompos(pos);
displayfor();
printf("\n Kushdeep Singh ");
Sleep(1000); break;
case 4:
break;
default:
printf("\n Wrong Choice ");
}
}
while(ch3!=4);
Sleep(4000); break;
case 6: return 0;
default:
printf("\n Wrong Choice ");
}
}
while(ch!=6);
return 0;
}