-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMultiList.cpp
133 lines (119 loc) · 2.24 KB
/
MultiList.cpp
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
#include <stdio.h>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
struct node
{
char name[20];
int cgpa;
node *next;
};
struct branch
{
char branchname[20];
branch *down;
node *next;
};
branch *head=NULL;
void menu()
{
system("cls");
cout << "1. Insert a new branch" << endl;
cout << "2. Add student details" << endl;
cout << "3. Show toppers" << endl;
cout << "4. Exit" << endl;
cout << "Input: ";
}
void createbranch()
{
branch *temp = new branch;
cout << "Enter branch name: ";
cin >> temp->branchname;
temp->next=NULL;
temp->down=NULL;
if(head==NULL)
head=temp;
else
{
branch *t = head;
while(t->down!=NULL)
t=t->down;
t->down=temp;
}
}
void addstudent()
{
branch *t=head;
node *temp= new node;
temp->next=NULL;
cout << "Enter name: ";
cin >> temp->name;
cout << "Enter cgpa: ";
cin >> temp->cgpa;
int i=0;
while(t!=NULL)
{
i++;
cout << i << ". " << t->branchname << endl;
t=t->down;
}
int input;
cout << "In: ";
cin >> input;
t=head;
for(int j=1; j<input; j++)
t=t->down;
//yeh vaala part thoda faulty hai. Upar ka sab sahi hai
if(t->next==NULL)
t->next=temp;
else
{
node *line=t->next;
while(line->next!=NULL)
line=line->next;
line->next=temp;
}
}
void show()
{
branch *t=head;
while(t!=NULL)
{
cout << t->branchname << endl;
node *line=t->next;
while(line!=NULL)
{
cout << line->name << " ";
cout << line->cgpa;
cout << endl;
line=line->next;
}
t=t->down;
}
}
int main()
{
int input;
do
{
menu();
cin >> input;
switch(input)
{
case 1:
//insert new branch
createbranch();
break;
case 2:
//add student
addstudent();
break;
case 3:
show();
break;
default:
break;
}
system("pause");
}while(input!=4);
}