- Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathFCFSScheduling.java
47 lines (36 loc) · 1.33 KB
/
FCFSScheduling.java
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
packagecom.thealgorithms.scheduling;
importcom.thealgorithms.devutils.entities.ProcessDetails;
importjava.util.List;
/**
* Non-pre-emptive First Come First Serve scheduling. This can be understood here -
* https://www.scaler.com/topics/first-come-first-serve/
*/
publicclassFCFSScheduling {
privateList<ProcessDetails> processes;
FCFSScheduling(finalList<ProcessDetails> processes) {
this.processes = processes;
}
publicvoidscheduleProcesses() {
evaluateWaitingTime();
evaluateTurnAroundTime();
}
privatevoidevaluateWaitingTime() {
intprocessesNumber = processes.size();
if (processesNumber == 0) {
return;
}
intwaitingTime = 0;
intburstTime = processes.get(0).getBurstTime();
processes.get(0).setWaitingTime(waitingTime); // for the first process, waiting time will be 0.
for (inti = 1; i < processesNumber; i++) {
processes.get(i).setWaitingTime(waitingTime + burstTime);
waitingTime = processes.get(i).getWaitingTime();
burstTime = processes.get(i).getBurstTime();
}
}
privatevoidevaluateTurnAroundTime() {
for (finalvarprocess : processes) {
process.setTurnAroundTimeTime(process.getBurstTime() + process.getWaitingTime());
}
}
}