-
Notifications
You must be signed in to change notification settings - Fork 0
/
Assignment 11
199 lines (182 loc) · 3.28 KB
/
Assignment 11
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
Assignmentno.:11
Title: Accept input as a string and construct a Doubly Linked List (DLL) for the input string with each node contains, as a data one character from the string and perform:
a) Insert b) delete c) Display forward, d) Display backward.
#include<stdio.h>
#include<string.h>
#include<malloc.h>
struct DLL
{
struct DLL *prev;
int roll_no;
char name[10];
float per;
struct DLL *next;
};
struct DLL *create(struct DLL *start);
struct DLL *dele(struct DLL *start);
void modify(struct DLL *start);
void display(struct DLL *start);
void displayback(struct DLL *start);
int main()
{
struct DLL *start=NULL;
int ch;
do
{
printf("\nMENU\n1.create\n2.Display forword\n3.modify\n4.dele\n5.display backword\n6.exit");
printf("enter your choice");
scanf("%d",&ch);
switch(ch)
{
case 1:start=create(start);
break;
case 2:display (start);
break;
case 3:modify(start);
break;
case 4:start=dele(start);
break;
case 5:displayback(start);
break;
}
}while(ch!=6);
}
struct DLL *create(struct DLL *start)
{
struct DLL *p,*q;
int i,r,n;
char stud_name[10];
float stud_per;
printf("\nEnter how many nodes to create:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter student roll no:");
scanf("%d",&r);
printf("Enter student name:");
scanf("%s",stud_name);
printf("Enter student percentage:");
scanf("%f",&stud_per);
p=(struct DLL *)malloc(sizeof(struct DLL));
p->roll_no=r;
strcpy(p->name,stud_name);
p->per=stud_per;
p->prev=NULL;
p->next=NULL;
if(start==NULL)
{
start=p;
}
else
{
q=start;
while(q->next!=NULL)
{
q=q->next;
}
p->prev=q;
q->next=p;
}
}
display(start);
return(start);
}
void display(struct DLL *start)
{
struct DLL *q;
if(start==NULL)
{
printf("\nLIST IS EMPTY");
}
else
{
q=start;
printf("\n\tROLL NO\tNAME\tPERCENTAGE\n");
while(q!=NULL)
{
printf("\n\t%d\t%s\t%f",q->roll_no,q->name,q->per);
q=q->next;
}
}
}
void displayback(struct DLL *start)
{
struct DLL *q;
if(start==NULL)
{
printf("\nLIST IS EMPTY");
}
else
{
q=start;
while(q->next!=NULL)
{
q=q->next;
}
printf("\n\tROLL NO\tNAME\tPERCENTAGE\n");
while(q!=NULL)
{
printf("\n\t%d\t%s\t%f",q->roll_no,q->name,q->per);
q=q->prev;
}
}
}
struct DLL *dele(struct DLL *start)
{
struct DLL *q;
int r;
printf("\nEnter the roll no of student to dele:");
scanf("%d",&r);
if(start==NULL)
{
printf("\nLIST IS EMPTY");
}
q=start;
while(q->roll_no!=r && q!=NULL)
{
q=q->next;
}
if(q!=NULL)
{
q->prev->next=q->next;
q->next->prev=q->prev;
free(q);
}
display(start);
return(start);
}
void modify(struct DLL *start)
{
struct DLL *q;
int i,r,n;
char stud_name[10];
float stud_per;
printf("\nEnter the roll no of student to modify:");
scanf("%d",&r);
if(start==NULL)
{
printf("\nLIST IS EMPTY");
}
q=start;
while(q->roll_no!=r && q!=NULL)
{
q=q->next;
}
if(q->roll_no==r)
{
printf("Enter new roll no:");
scanf("%d",&r);
printf("Enter new name:");
scanf("%s",stud_name);
printf("Enter new percentage:");
scanf("%f",&stud_per);
q->roll_no=r;
strcpy(q->name,stud_name);
q->per=stud_per;
}
else
{
printf("NOT FOUND");
}
display(start);
}