-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLLMENU.C
More file actions
294 lines (291 loc) · 7.25 KB
/
LLMENU.C
File metadata and controls
294 lines (291 loc) · 7.25 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
#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;
}*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;
if(start==NULL)
start=new_node;
else
{
node=start;
while(node->next!=NULL)
node=node->next;
node->next=new_node;
}
}
void display()
{
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 addtobeg(int rn,char a[])
{
struct node *new_node;
new_node=(struct node *)malloc(sizeof(struct node));
new_node->roll_num=rn;
strcpy(new_node->name,a);
new_node->next=start;
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;
new_node->next=node->next;
node->next=new_node;
}
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=new_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 rev()
{
struct node *p1,*p2,*p3;
if(start->next==NULL)
return;
p1=start;
p2=p1->next;
p3=p2->next;
p1->next=NULL;
p2->next=p1;
while(p3!=NULL)
{
p1=p2;
p2=p3;
p3=p3->next;
p2->next=p1;
}
start=p2;
}
void delfrombeg()
{
struct node *node=start;
if(node==NULL)
{
printf("\n Underflow error ");
return;
}
else
start=node->next;
return;
}
void delfromend()
{
struct node *node=start;
if(node==NULL)
{
printf("\n Underflow error ");
}
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 ");
}
while(c<node_no-1)
{
node=node->next;
c++;
}
node->next=node->next->next;
}
int main()
{
int ch1,ch2,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: Reverse ");
printf("\n 6: Deletion ");
printf("\n 7: 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);
display();
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);
display();
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);
display();
printf("\n Kushdeep Singh ");
Sleep(1000); break;
case 4:
break;
default:
printf("\n Wrong Choice ");
}
}
while(ch1!=4);
Sleep(4000); break;
case 3:
display();
printf("\n Kushdeep Singh ");
Sleep(4000); break;
case 4:
count();
Sleep(4000); break;
case 5:
rev();
display();
printf("\n Kushdeep Singh ");
Sleep(4000); break;
case 6:
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",&ch2);
switch(ch2)
{
case 1:
delfrombeg();
display();
printf("\n Kushdeep Singh ");
Sleep(1000); break;
case 2:
delfromend();
display();
printf("\n Kushdeep Singh ");
Sleep(1000); break;
case 3:
printf("\n Enter the record number to delete ");
scanf("%d",&pos);
delfrompos(pos);
display();
printf("\n Kushdeep Singh ");
Sleep(1000); break;
case 4:
break;
default:
printf("\n Wrong Choice ");
}
}
while(ch2!=4);
Sleep(4000); break;
case 7: return 0;
default:
printf("\n Wrong Choice ");
}
}
while(ch!=7);
return 0;
}