-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent_SLL.c
More file actions
185 lines (185 loc) · 3.77 KB
/
Student_SLL.c
File metadata and controls
185 lines (185 loc) · 3.77 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
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct node
{
char usn[20];
char name[20];
char branch[20];
int sem;
char phno[20];
struct node *link;
};
typedef struct node *NODE;
//insert front
NODE IF(char usn[],char name[],char branch[],int sem,char phno[],NODE first)
{
NODE temp;
temp=(NODE)malloc(sizeof(struct node));
strcpy(temp->usn,usn);
strcpy(temp->name,name);
strcpy(temp->branch,branch);
temp->sem=sem;
strcpy(temp->phno,phno);
temp->link=NULL;
if(first==NULL)
return temp;
temp->link=first;
return temp;
}
//insert rear
NODE IR(char usn[],char name[],char branch[],int sem,char phno[],NODE first)
{
NODE temp;
temp=(NODE)malloc(sizeof(struct node));
strcpy(temp->usn,usn);
strcpy(temp->name,name);
strcpy(temp->branch,branch);
temp->sem=sem;
strcpy(temp->phno,phno);
temp->link=NULL;
if(first==NULL)
return temp;
NODE cur;
cur=first;
while(cur->link!=NULL)
cur=cur->link;
cur->link=temp;
return first;
}
//delete front
NODE DF(NODE first)
{
if(first==NULL)
{
printf("The list is empty\n");
return first;
}
NODE cur;
cur=first;
first=first->link;
printf("The student details deleted are:\n");
printf("Name:%s\nUSN:%s\nBranch:%s\nSem:%d\nPhno:%s\n",cur->name,cur->usn,cur->branch,cur->sem,cur->phno);
free(cur);
return first;
}
//delete rear
NODE DR(NODE first)
{
if(first==NULL)
{
printf("The list is empty\n");
return first;
}
if(first->link==NULL)
{
printf("The student details deleted are:\n");
printf("Name:%s\nUSN:%s\nBranch:%s\nSem:%d\nPhno:%s\n",first->name,first->usn,first->branch,first->sem,first->phno);
free(first);
return NULL;
}
NODE cur,prev;
cur=first;
prev=NULL;
while(cur->link!=NULL)
{
prev=cur;
cur=cur->link;
}
printf("The student details deleted are:\n");
printf("Name:%s\nUSN:%s\nBranch:%s\nSem:%d\nPhno:%s\n",cur->name,cur->usn,cur->branch,cur->sem,cur->phno);
free(cur);
prev->link=NULL;
return first;
}
//display
void disp(NODE first)
{
int count=0;
if(first==NULL)
{
printf("The list is empty\n");
printf("The no of nodes are %d\n",count);
return;
}
NODE cur=first;
printf("The contents of the list are:\n");
while(cur!=NULL)
{
count++;
printf("Name:%s\nUSN:%s\nBranch:%s\nSem:%d\nPhno:%s\n",cur->name,cur->usn,cur->branch,cur->sem,cur->phno);
printf("-----------------------------------------------\n");
cur=cur->link;
}
printf("The no of nodes are %d\n",count);
return;
}
//main
void main()
{
char usn[20];
char name[20];
char branch[20];
int sem;
char phno[20];
NODE first=NULL;
int n,choice;
printf("Enter the no of students:\n");
scanf("%d",&n);
for(int i=0;i<n;i++)
{
printf("For student %d\n",i+1);
printf("usn:\n");
scanf("%s",usn);
printf("name:\n");
scanf("%s",name);
printf("branch:\n");
scanf("%s",branch);
printf("sem:\n");
scanf("%d",&sem);
printf("phno:\n");
scanf("%s",phno);
first=IF(usn,name,branch,sem,phno,first);
}
for(;;)
{
printf("1.IF\n2.IR\n3.DF\n4.DR\n5.Disp\n6.Exit\nEnter choice:\n");
scanf("%d",&choice);
switch(choice)
{
case 1: printf("Enter student details:\n");
printf("usn:\n");
scanf("%s",usn);
printf("name:\n");
scanf("%s",name);
printf("branch:\n");
scanf("%s",branch);
printf("sem:\n");
scanf("%d",&sem);
printf("phno:\n");
scanf("%s",phno);
first=IF(usn,name,branch,sem,phno,first);
break;
case 2: printf("Enter student details:\n");
printf("usn:\n");
scanf("%s",usn);
printf("name:\n");
scanf("%s",name);
printf("branch:\n");
scanf("%s",branch);
printf("sem:\n");
scanf("%d",&sem);
printf("phno:\n");
scanf("%s",phno);
first=IR(usn,name,branch,sem,phno,first);
break;
case 3: first=DF(first);
break;
case 4: first=DR(first);
break;
case 5: disp(first);
break;
case 6: exit(0);
}
}
}