-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShortJobFirst.java
More file actions
43 lines (40 loc) · 1.42 KB
/
ShortJobFirst.java
File metadata and controls
43 lines (40 loc) · 1.42 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
package my.exercises.shortjob;
public class ShortJobFirst {
public static final MyQueueLinked readyQ = new MyQueueLinked();
public static void jobDisplayFormat(Job job) {
System.out.printf("\tJob Size: %d | ", job.getJobSize());
}
public static void displayRQ(){
for(int i= readyQ.size(); i !=0; i--){
Job job = (Job) readyQ.dequeue();
jobDisplayFormat(job);
readyQ.enqueue(job);
}
}
public static void setReadyQ(Job job) {
final MyQueueLinked greaterJobs = new MyQueueLinked();
for(int i = readyQ.size(); i!=0; i--){
Job currentJob = (Job) readyQ.dequeue();
if(currentJob.compareTo(job) > 0) greaterJobs.enqueue(currentJob);
else readyQ.enqueue(currentJob);
}
readyQ.enqueue(job);
while(!greaterJobs.isEmpty()) readyQ.enqueue(greaterJobs.dequeue());
}
public static void main(String[] args){
Job[] jobQueue = {
new Job(1, 40, 1, 1),
new Job(2, 10, 2, 2),
new Job(3, 10, 3, 3),
new Job(4, 20, 4, 4),
new Job(5, 30, 5, 4),
};
System.out.println("In Queue Jobs: ");
for(Job job: jobQueue) {
jobDisplayFormat(job);
setReadyQ(job);
}
System.out.println("\nReady Queue: ");
displayRQ();
}
}