-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathallocate_lectures.cpp
89 lines (86 loc) · 3.2 KB
/
allocate_lectures.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
#include "ds.h"
bool allocate_lecture(course* IC, int l, bool tut, slot *& head){
// cout<<"allocating lecture for "<< IC->course_code<<" " << l <<endl;
cout<<l<<endl;
slot* temp_slot = new slot();
temp_slot->day = 0;
temp_slot->time_slot = 0;
bool flag = 0;
while(l > 0){
// cout<<"lecture left "<<l<<endl;
while(temp_slot->day < working_days || temp_slot->time_slot < no_of_slots){
bool flag_busy = 0;
for(int i=0 ; i< dept.size(); i++){
instructor * x = map_instructor[IC->course_code];
bool a = checkmy_instructor_slot(x ,temp_slot);
if( (dept[i]->table[temp_slot->day][temp_slot->time_slot]).first != 0 && a ){
flag_busy = 1;
if(temp_slot->time_slot < no_of_slots - 1){
// cout<<"next slot"<<endl;
temp_slot->time_slot += 1;
// cout<<temp_slot->day<<" "<<temp_slot->time_slot<<endl;
}
else{
// cout<<"next day"<<endl;
temp_slot->day += 1;
temp_slot->time_slot = 0;
// cout<<temp_slot->day<<" "<<temp_slot->time_slot<<endl;
}
break;
}
}
if(flag_busy == 0){
// cout<<"lecture allocated"<<endl;
flag =1;
// cout<<"enter"<<temp_slot->day<<" ";
// cout<<temp_slot->time_slot<<endl;
if( head == NULL){
head = temp_slot;
temp_slot = new slot();
temp_slot->day = head->day +1;
}
else{
slot* temp = head;
while(temp->next != NULL){
temp = temp->next;
}
temp->next = temp_slot;
temp_slot = new slot();
// cout<<temp->day<<endl;
temp_slot->day = temp->next->day +1;
}
temp_slot->time_slot = 0;
l--;
break;
}
}
if(flag == 0){
cout << "ERRORRRRR: THE COURSE" << IC->course_code << "COULDN'T GET ALL LECTURES ALLOTED "<< l <<"lectures left"<<endl;
head = NULL;
return false;
}
}
slot * temp = head;
// if(temp){
// cout<<"its not null"<<endl;
// }
// else{
// cout<<"its nulll"<<endl;
// }
while(temp){
cout<<"allocating "<<IC->course_code<<" "<<temp->day<<" "<<temp->time_slot <<endl;
for(int i=0; i<dept.size(); i++){
if(tut){
dept[i]->table[temp->day][temp->time_slot] = make_pair(2,IC) ;
cout<<"tutorial" << dept[i]->table[temp->day][temp->time_slot].first<<endl;
}
else{
dept[i]->table[temp->day][temp->time_slot] = make_pair(1,IC) ;
// dept[i]->table[temp->day][temp->time_slot].second = IC;
}
}
temp = temp->next;
}
cout<<endl;
return true;
}