-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstackImplementation.c
150 lines (112 loc) · 2.51 KB
/
stackImplementation.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
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct snode{
char name [20];
char eNo [10];
struct snode * studentNext;
struct cnode * courseNext;
};
typedef struct snode *studentNode;
struct cnode{
char courseNo [10];
struct cnode * courseNext;
};
typedef struct cnode * courseNode;
void insertStudentdata( char ENo[],char Name[]);
void insertCoursedata( char Courses[]);
//void printcourses();
void showlist();
studentNode studenthead = NULL;
courseNode coursehead = NULL;
int main (){
char i;
char Name[20]; char ENo[10];
char Courses[10];
printf("Do you have detais?(Y or N): \n");
scanf("%c",&i);
if(i=='Y'){
while(i=='Y'){
printf("Enter E.No :");
scanf("%s",ENo);
printf("\n");
printf("Enter Name :");
scanf("%s",Name);
printf("\n");
printf("Enter Courses :");
scanf("%s",Courses);
printf("\n");
while(strcmp(Courses,"End")){
insertCoursedata(Courses);
scanf("%s%*c",Courses);
}
insertStudentdata(ENo,Name);
printf("Do you have detais?(Y or N): \n");
scanf("%c",&i);
}
showlist();
}
else{
showlist();
return 0;
}
return 0;
}
void insertStudentdata(char ENo[],char Name[]){
studentNode new_snode= (studentNode)malloc(sizeof (struct snode));
studentNode tmp;
tmp = studenthead;
if(tmp){
while(tmp->studentNext){
tmp = tmp->studentNext;
}
tmp -> studentNext = new_snode;
}
else{
studenthead = new_snode;
}
new_snode->courseNext=coursehead;
coursehead = NULL;
//insertCoursedata( Courses);
strcpy(new_snode->name,Name);
strcpy(new_snode->eNo , ENo);
new_snode->studentNext=NULL;
return;
}
void insertCoursedata ( char Courses[]){
courseNode new_cnode=(courseNode)malloc(sizeof(struct cnode));
courseNode tmp1;
tmp1=coursehead;
new_cnode->courseNext=NULL;
strcpy(new_cnode->courseNo,Courses);
if(tmp1){
while(tmp1->courseNext){
tmp1 = tmp1->courseNext;
}
tmp1 -> courseNext = new_cnode;
}else{
coursehead = new_cnode;
}
return;
}
void printcourses(courseNode courseNext){
courseNode tmp;
tmp= courseNext;
printf("Courses :");
while(tmp){
printf("%s\t",tmp->courseNo);
tmp=tmp->courseNext;
}
//tmp=tmp->studentNext;
}
void showlist(){
studentNode tmp;
tmp= studenthead;
while(tmp){
printf("\n");
printf("E_Number :%s\n",tmp->eNo);
printf("Name : %s\n",tmp->name);
printcourses(tmp -> courseNext);
tmp=tmp->studentNext;
}
}