Okay
I am working on a quick Shortest Job first algorithm and ran into a problem. I can't figure a way to implement, each way I try I get the wrong next process.
private static int lowTIme(ArrayList<Process> testProcesss,
int currTime) {
int i;
int temp = testProcesss.get(0).getcpuTime();
for(i = 1; currTime > testProcesss.get(i).getArrivalTime()
&& temp < testProcesss.get(i).getcpuTime(); i++){
temp = testProcesss.get(i).getcpuTime();
}
return 0;
}
Example
Process: 1
Arrival Time: 0
CPU Time: 5
Process: 2
Arrival Time: 2
CPU Time: 1
Process: 3
Arrival Time: 3
CPU Time: 8
Process: 4
Arrival Time: 3
CPU Time: 3
Okay first time around it will choose Process 1, the next would be 2, and the 3.
But it will choose process 2, even though it hasn't arrived
Any help?