-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessTable.cpp
More file actions
137 lines (129 loc) · 3.07 KB
/
ProcessTable.cpp
File metadata and controls
137 lines (129 loc) · 3.07 KB
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
#include "ProcessTable.h"
/*******************************************************************************
- Process Table contains all processes that need to be executed
- Each list in Process Table will contain pointer which point to the top
current event of each process in Input Table
********************************************************************************/
ProcessTable::ProcessTable()
{
top = NULL;
ptr = NULL;
empty = true;
count = 0;
}
ProcessTable::~ProcessTable()
{
}
ProcessTable* ProcessTable::push(ProcessTable* table, int start, int end, int ID, InputList* current, string status)
{
List* newList;
count++;
if (empty)
{
empty = false;
newList = new List();
newList->startTime = start;
newList->endTime = end; newList->processID = ID;
newList->currentProcess = current;
newList->status = status;
newList->next = NULL; newList->prev = NULL;
table->ptr = table->top = newList;
}
else
{
newList = new List();
newList->startTime = start;
newList->endTime = end; newList->processID = ID;
newList->currentProcess = current;
newList->status = status;
table->ptr->next = newList;
newList->next = NULL; newList->prev = table->ptr;
table->ptr = newList;
}
return table;
}
List* ProcessTable::searchList(ProcessTable* table, int ID)
{
List* list;
list = table->top;
while (list->processID != ID)
{ list = list->next; }
return list;
}
ProcessTable* ProcessTable::update(ProcessTable* table, int end,int ID, InputList* current, string status)
{
List* list;
list = table->searchList(table, ID);
list->endTime = end;
list->currentProcess = current;
list->status = status;
return table;
}
List* ProcessTable::getList(ProcessTable* table)
{
List* newList;
newList = table->top;
return newList;
}
ProcessTable* ProcessTable::pop(ProcessTable* table)
{
List* list;
count--;
list = table->top;
while (list->status != "TERMINATED")
{
list = list->next;
}
if (list->next == NULL && count != 0)
{
list->prev->next = NULL;
table->ptr = list->prev;
}
else if (list->prev == NULL && count != 0)
{
list->next->prev = NULL;
table->top = list->next;
}
else if (list->prev != NULL && list->next != NULL)
{
list->next->prev = list->prev;
list->prev->next = list->next;
}
else if (count == 0)
{
table->ptr = table->top = NULL;
empty = true;
}
delete list;
return table;
}
bool ProcessTable::exist(ProcessTable* table, List* list)
{
if (table->count == 0) return false;
List* temp = table->top;
do
{
if (temp->currentProcess == list->currentProcess) return true;
if (temp->next != NULL) temp = temp->next;
else break;
} while (1);
return false;
}
int ProcessTable::minEndTime(ProcessTable* table)
{
int min = INT_MAX;
List* list = table->top;
do
{
if (list->endTime < min) min = list->endTime;
if (list->next != NULL) list = list->next;
else break;
} while (1);
return min;
}
bool ProcessTable::complete(ProcessTable* table)
{
if (table->count == 0)
return true;
return false;
}