-
Notifications
You must be signed in to change notification settings - Fork 32
/
MultiList.cpp
91 lines (71 loc) · 1.75 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
#include<bits/stdc++.h>
using namespace std;
struct node {
int slot;
string subject;
node *next;
};
class multiList {
node *week_heads[6];
public:
multiList() {
for (int i = 0 ; i < 6 ; i++)
week_heads[i] = NULL;
}
void insert(int w, node *n) {
node *temp;
if ((week_heads[w] == NULL) || ((week_heads[w]->slot) >= (n->slot))) {
n->next = week_heads[w];
week_heads[w] = n;
}
else {
temp = week_heads[w];
while (temp->next != NULL && temp->next->slot < n->slot)
temp = temp->next;
n->next = temp->next;
temp->next = n;
}
cout << "\n\t=> Slot added Successfully\n\n";
}
void printWeekDaySchedule(int lNo) {
node *itr = week_heads[lNo];
cout << "\nOn WeekDay-" << lNo + 1 << ":";
while (itr != NULL) {
cout << "\n\tSlot: " << itr->slot << " -> Subject: " << itr->subject;
itr = itr->next;
}
cout << endl;
}
void showTimeTable() {
for (int i = 0 ; i < 6 ; i++)
printWeekDaySchedule(i);
}
};
int main() {
multiList timeTable;
int week, timeSlot;
string subj;
int opt;
cout << "***** MultiList *****" << endl;
do {
cout << "\tSelect from the given options: \n";
cout << "\t\t1.) Add Slot in Time Table\n\t\t2.) Show TimeTable\n";
cout << "\t\tOption: ";
cin >> opt;
if (opt == 1) {
node *newNode = new node;
cout << "\t\t\tOn which Day of Week ?\n\t\t\t=> ";
cin >> week;
cout << "\t\t\tIn which Slot ?\n\t\t\t=> ";
cin >> timeSlot;
cout << "\t\t\tWhich Subject ?\n\t\t\t=> ";
cin >> subj;
newNode->slot = timeSlot;
newNode->subject = subj;
newNode->next = NULL;
timeTable.insert(week - 1, newNode);
}
} while (opt == 1);
timeTable.showTimeTable();
return 0;
}