-
Notifications
You must be signed in to change notification settings - Fork 0
/
myHelperFunctions.h
84 lines (76 loc) · 2.24 KB
/
myHelperFunctions.h
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
#pragma
//more the value of this=> lesser will be the crashes, great time ave at takeoff, and lesser at landing
const int LOW_FUEL_LIMIT = 2;
int IsEmergencyLanding(MinPeriorityQueue <Plane> patterns[], int time)
{
for (int i = 0; i < 4; i++)//THERE ARE TOTAL FOUR QUEUE TO CHECK FOR THAT PLANE
{
if (patterns[i].isEmpty() == false)
{
int diff = (patterns[i].top()).getSecondTime() - time;
if (diff < LOW_FUEL_LIMIT)//means only last time unit has left of his life (:D)
return i;
}
}
return -1;//-1 => no emergency landing
}
int WhichHasLeastSizeREV(QueueSLL <Plane> *list, const int & _size)
{
int minIndex = 2; //we prefer to take off at runway three (special devoted for take off)
for (int i = _size - 1; i >= 0; --i)
{
int t = list[i].size();
if (t < list[minIndex].size())
{
minIndex = i;
}
}
return minIndex;
}
int WhichHasLeastSize(MinPeriorityQueue <Plane> *list, const int & _size)
{
int minIndex = 0;
for (int i = 0; i < _size; i++)//we know there are 4 patterns (constants)
{
int t = list[i].size();
if (t < list[minIndex].size())
minIndex = i;
}
return minIndex;
}
int WhichHasMaxSize(MinPeriorityQueue <Plane> list[], const int & _size)
{
int max = 0;
for (int i = 0; i < _size; i++)//we know there are 4 patterns (constants)
{
int t = list[i].size();
if (t > list[max].size())
max = i;
}
return max;
}
void SaveAirportState(ofstream & OutputFile, MinPeriorityQueue<Plane>HoldingPatterns[], QueueSLL<Plane> takeOffQueue[])
{
OutputFile << "Sizes of H_Pattern(respectively) [";
for (int j = 0; j < 4; j++)
OutputFile << HoldingPatterns[j].size() << " ";
OutputFile << "] & ";
OutputFile << "Top elements of H_Pattern: {";
for (int j = 0; j < 4; j++){
if (!HoldingPatterns[j].isEmpty())
(HoldingPatterns[j].top()).printToFile(OutputFile);
else OutputFile << " EMPTY ";
}
OutputFile<<"}" << endl;
OutputFile << "Sizes of Take off queues (respectively) [";
for (int j = 0; j < 3; j++)
OutputFile << takeOffQueue[j].size() << " ";
OutputFile << "] & ";
OutputFile << "Top elements of take off queue: {";
for (int j = 0; j < 3; j++){
if (!takeOffQueue[j].isEmpty())
(takeOffQueue[j].top()).printToFile(OutputFile);
else OutputFile << " EMPTY ";
}
OutputFile << "}" << endl;
}