-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSLL.c
167 lines (167 loc) · 3.67 KB
/
SLL.c
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
#include<stdio.h>
#include<string.h>
#include<malloc.h>
int i,choice,n,sem,ph,a,b;
char option;
char name[20];
char usn[20];
char br[20];
struct node{
char USN[20];
char Name[20];
char Branch[20];
int Sem;
int PhoneNo;
struct node* link;
}*h,*ptr,*p=NULL,*t;
Create()
{
printf("How many Student Record You Want:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
ptr=(struct node*)malloc(sizeof(struct node));
if(p==NULL)
ptr->link=NULL;
else
ptr->link=p;
printf("Enter %dth Student USN:",n-i);
scanf("%s",&usn);
strcpy(ptr->USN,usn);
printf("Enter %dth Student Name:",n-i);
scanf("%s",&name);
strcpy(ptr->Name,name);
printf("Enter %dth Student's Branch:",n-i);
scanf("%s",&br);
strcpy(ptr->Branch,br);
printf("Enter %dth Student's Sem:",n-i);
scanf("%d",&sem);
ptr->Sem=sem;
printf("Enter %dth Phone No.",n-i);
scanf("%d",&ph);
ptr->PhoneNo=ph;
p=ptr;
}
}
Show()
{
if(n==0)
printf("...................Empty List...................");
else
{
ptr=p;
for(i=0;i<n;i++)
{
printf("USN=%s ",ptr->USN);
printf("Name=%s ",ptr->Name);
printf("Branch=%s ",ptr->Branch);
printf("Sem=%d ",ptr->Sem);
printf("PHONE No=%d \n\n",ptr->PhoneNo);
ptr=ptr->link;
}
ptr=p;
}
}
Add()
{
printf("Enter Node At Which You Want to Insert A New Student Record (Node Started From Zero):\n");
scanf("%d",&a);
if(a<=n)
{
for(i=0;i<a-1;i++)
ptr=ptr->link;
h=(struct node*)malloc(sizeof(struct node));
printf("Enter Student USN:");
scanf("%s",&usn);
strcpy(h->USN,usn);
printf("Enter Student Name:");
scanf("%s",&name);
strcpy(h->Name,name);
printf("Enter Student's Branch:");
scanf("%s",&br);
strcpy(h->Branch,br);
printf("Enter Student's Sem:");
scanf("%d",&sem);
h->Sem=sem;
printf("Enter Phone No.");
scanf("%d",&ph);
h->PhoneNo=ph;
if(a==0)
{
h->link=ptr;
p=h;
}
else
{
h->link=ptr->link;
ptr->link=h;
}
n++;
}
else
printf("..................Invalid Node At which You Want to Insert................... ");
}
Delete()
{
if(n==0)
printf("....................Empty List.................");
else
{
printf("Enter Node no. Which You Want To Delete started with Zero:\n");
scanf("%d",&b);
if(b<n)
{
for(i=0;i<b-1;i++)
ptr=ptr->link;
if(b==0)
{
t=ptr;
p=ptr->link;
}
else
{
t=ptr->link;
if(b==n-1)
ptr->link=NULL;
else
ptr->link=t->link;
}
free(t);
n--;
}
else
printf("..................Invalid Node To Be Deleted.................");
}
}
Count()
{
printf("\nNo Of Student In the Record=%d ",n);
}
main()
{
do{
printf("Choose An Option from the Following:\n");
printf("1:Create Student Record:\n");
printf("2:Show Student Record:\n");
printf("3:Add a Student Record At Any Position:\n");
printf("4:Delete a Student Record:\n");
printf("5:To Count NO. Of Student In Record:\n");
scanf("%d",&choice);
switch(choice)
{
case 1:Create();
break;
case 2:Show();
break;
case 3:Add();
break;
case 4:Delete();
break;
case 5:Count();
break;
default: printf(".....................Invalid Choice.....................");
}
printf("\n\nDo you Want to Continue (y/n): ");
scanf("%s",&option);
} while(option=='y'||option=='Y');
}