-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclo1.cpp
More file actions
157 lines (145 loc) · 3.86 KB
/
clo1.cpp
File metadata and controls
157 lines (145 loc) · 3.86 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include "clo1.h"
void createList(list &L){
first(L) = nil;
}
address createElement(job j){
address P = new element;
info(P) = j;
next(P) = nil;
return P;
}
void insertLast(list &L, address P){
address Q = first(L);
if (first(L) == nil){
first(L) = P;
}else{
while(next(Q) != nil){
Q = next(Q);
}
next(Q) = P;
}
}
void deleteLast(list &L, address &P){
address Q = first(L);
while(next(Q)!= nil){
Q = next(Q);
}
P = next(Q);
next(Q) = nil;
}
address shortestJob(list L){
address P = first(L);
address Q;
int shortest = 999;
while(P != nil){
if (info(P).burstTime < shortest){
shortest = info(P).burstTime;
Q = P;
}
P = next(P);
}
return Q;
}
void printJob(address P){
cout<<endl<<"=======PrintJob========"<<endl;
cout<<"jobCode dengan burst time terkecil adalah"<<endl;
cout<<info(P).jobCode<<"\t"<<info(P).burstTime<<endl;
cout<<endl;
}
void printAllJob(list L){
address P = first(L);
cout<<endl<<"=======PrintAllJob========"<<endl;
cout<<"jobCode\t\t"<<"burstTime"<<endl;
if (first(L) != nil){
while (P!=nil){
cout<<info(P).jobCode<<"\t\t"<<info(P).burstTime<<endl;
P=next(P);
}
}else{
cout<<"List Kosong"<<endl;
}
cout<<endl;
}
void firstComeFirstServe(list &L){
address P = first(L);
int tempWT = 0;
int tempTAT = 0;
int totalWT = 0;
int totalTAT = 0;
float averageWT;
float averageTAT;
cout<<"waiting time dari ";
while(P!=nil){
if (P == first(L)){
info(P).waitingTime = 0;
tempWT = tempWT + info(P).burstTime;
totalWT = totalWT + info(P).waitingTime;
cout<<info(P).jobCode<<"="<<info(P).waitingTime;
}else{
info(P).waitingTime = tempWT;
tempWT = tempWT + info(P).burstTime;
totalWT = totalWT + info(P).waitingTime;
cout<<info(P).jobCode<<"="<<info(P).waitingTime;
}
if(next(P)!=nil){
cout<<",";
}
P = next(P);
}
cout<<endl;
int N = 1;
P = first(L);
cout<<"average time dari waiting time adalah = ";
while(P!=nil){
if (P == first(L)){
cout<<"("<<info(P).waitingTime;
}else{
cout<<info(P).waitingTime;
}
if(next(P)!=nil){
cout<<"+";
}
N++;
P = next(P);
}
averageWT = float(totalWT) / float(N);
cout<<") / "<<N<<" = "<<averageWT<<endl;
P = first(L);
cout<<"turn around time dari ";
while(P!=nil){
if (P == first(L)){
info(P).turnAroundTime = info(P).burstTime;
tempTAT = tempTAT + info(P).burstTime;
totalTAT = totalTAT + info(P).turnAroundTime;
cout<<info(P).jobCode<<"="<<info(P).turnAroundTime;
}else{
info(P).turnAroundTime = tempTAT + info(P).burstTime;
tempTAT = tempTAT + info(P).burstTime;
totalTAT = totalTAT + info(P).turnAroundTime;
cout<<info(P).jobCode<<"="<<info(P).turnAroundTime;
}
if(next(P)!=nil){
cout<<",";
}
P = next(P);
}
cout<<endl;
N = 1;
P = first(L);
cout<<"average time dari turn around time adalah = ";
while(P!=nil){
if (P == first(L)){
cout<<"("<<info(P).turnAroundTime;
}else{
cout<<info(P).turnAroundTime;
}
if(next(P)!=nil){
cout<<"+";
}
N++;
P = next(P);
}
averageTAT = float(totalTAT) / float(N);
cout<<") / "<<N<<" = "<<averageTAT<<endl;
}
void shortestJobFirst(list &L);