-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path7. Student-SLL.c
119 lines (111 loc) · 3.04 KB
/
7. Student-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
#include <stdio.h>
#include <stdlib.h>
struct node
{
struct node *next;
char name[25], usn[15], programme[10];
int sem;
int ph_no;
} *newnode, *head = NULL, *temp, *tail,*prev;
void create(){
newnode = (struct node *)malloc(sizeof(struct node));
newnode->next = NULL;
printf("\nEnter Name:");
scanf("%s", newnode->name);
printf("Enter USN:");
scanf("%s", newnode->usn);
printf("Enter Programme:");
scanf("%s", newnode->programme);
printf("Enter Sem:");
scanf("%d", &newnode->sem);
printf("Enter Phone Number:");
scanf("%d", &newnode->ph_no);
if (head == NULL){
tail = temp = head = newnode;
}
else{
temp->next = newnode;
temp=temp->next;
}
}
int insertfront(){
newnode = (struct node *)malloc(sizeof(struct node));
newnode->next = NULL;
printf("\nEnter Name:");
scanf("%s", newnode->name);
printf("Enter USN:");
scanf("%s", newnode->usn);
printf("Enter Programme:");
scanf("%s", newnode->programme);
printf("Enter Sem:");
scanf("%d", &newnode->sem);
printf("Enter Phone Number:");
scanf("%d", &newnode->ph_no);
newnode->next = head;
head = newnode;
}
int delfront(){
temp = head;
head = temp->next;
free(temp);
}
int insertend(){
newnode = (struct node *)malloc(sizeof(struct node));
printf("\nEnter Name:");
scanf("%s", newnode->name);
printf("Enter USN:");
scanf("%s", newnode->usn);
printf("Enter Programme:");
scanf("%s", newnode->programme);
printf("Enter Sem:");
scanf("%d", &newnode->sem);
printf("Enter Phone Number:");
scanf("%d", &newnode->ph_no);
temp=head;
while(temp->next!=NULL){
temp=temp->next;
}
temp->next=newnode;
newnode->next=NULL;
}
int delend(){
temp = head;
while (temp->next != NULL){
prev = temp;
temp = temp->next;
}
prev->next = NULL;
tail = prev;
free(temp);
}
void display(){
temp = head;
int count = 1;
while (temp != NULL){
printf("\nDetails of Student %d", count++);
printf("\nName:%s\nUsn:%s\nProgramme:%s\nSem:%d\nPhone Number:%d\n", temp->name, temp->usn, temp->programme, temp->sem, temp->ph_no);
temp = temp->next;
}
}
int main(){
int i, m, ch;
while (1){
printf("\nSingle linkedlist for Student details\n\n1.Create\n2.Insert at front\n3.Delete at front\n4.Insert at end\n5.Delete at end\n6.Display\n7.Exit\nEnter your choice:");
scanf("%d", &ch);
switch (ch)
{
case 1: printf("\nEnter No. of students:");
scanf("%d", &m);
for (i=0; i<m;i++){
create();}
break;
case 2:insertfront();break;
case 3:delfront();break;
case 4:insertend();break;
case 5:delend();break;
case 6:display();break;
case 7:exit(0);
default:printf("\ninvalid choice\n");break;
}
}
}