We have a homework about sorting ID, Arrival Time, CPU Burst Time, and Priority and I'm only having a problem on the sorting part which I could really use some help. Also, the value of the ID, AT, CBT, and Prio depends on the user input. I'm also using dual dimension Array to store the ID,AT,CBT, and P.
For example
ID: 98
AT: 50
CBT: 60
P(1 is the highest & 5 is the lowest): 1
ID: 99
AT: 55
CBT: 51
P: 1
if I want to arrange it based on AT, the one with the lower AT would be printed first along with it's ID and etc. The sequence would be from least to greatest AT.
and if I want to arrange it based on CBT, just like the AT, it would be printed from least to greatest, but if there if there are multiple CBT that are equal to each other, their AT would determine who would be printed first.
and if I arrange it based on priority, the prio with the value 1 would be printed first up to 5, but if there are multiple prio with same value, their CBT would determine who would be printed first, but if their CBT is the same too, it's up to AT to determine it.
I want to learn how to do it using java.
if(userchoice == '1'){
//infos[a][1] is where the AT value stored
if(infos[0][1] < [1][1] && infos[0][1] < infos[2][1] &&....infos[4][1]){
for(int b = 0;b<4;b++){
System.out.print(infos[0][]+"\t");
}
}
System.out.println();
if(infos[1][1] > infos[0][1] && infos[1][1] < infos[2][1] &&....infos[4][1]){
for(int b = 0;b<4;b++){
System.out.print(infos[1][b]+"\t");
}
}
}
these are the actual output based on my given example
Arranged using AT:
ID: 98
AT: 50
CBT: 60
P: 1
ID: 99
AT: 55
CBT: 51
P: 1
Arranged using CBT:
ID: 99
AT: 55
CBT: 51
P: 1
ID: 98
AT: 50
CBT: 60
P: 1
Arranged using P:
ID: 99
AT: 55
CBT: 51
P: 1
ID: 98
AT: 50
CBT: 60
P: 1