@@ -14,6 +14,18 @@ public class SJFScheduling {
1414 protected ArrayList <ProcessDetails > processes ;
1515 protected ArrayList <String > schedule ;
1616
17+ private static void sortProcessesByArrivalTime (List <ProcessDetails > processes ) {
18+ for (int i = 0 ; i < processes .size (); i ++) {
19+ for (int j = i + 1 ; j < processes .size () - 1 ; j ++) {
20+ if (processes .get (j ).getArrivalTime () > processes .get (j + 1 ).getArrivalTime ()) {
21+ final var temp = processes .get (j );
22+ processes .set (j , processes .get (j + 1 ));
23+ processes .set (j + 1 , temp );
24+ }
25+ }
26+ }
27+ }
28+
1729 /**
1830 * a simple constructor
1931 * @param processes a list of processes the user wants to schedule
@@ -22,22 +34,10 @@ public class SJFScheduling {
2234 SJFScheduling (final ArrayList <ProcessDetails > processes ) {
2335 this .processes = processes ;
2436 schedule = new ArrayList <>();
25- sortByArrivalTime ( );
37+ sortProcessesByArrivalTime ( this . processes );
2638 }
2739 protected void sortByArrivalTime () {
28- int size = processes .size ();
29- int i ;
30- int j ;
31- ProcessDetails temp ;
32- for (i = 0 ; i < size ; i ++) {
33- for (j = i + 1 ; j < size - 1 ; j ++) {
34- if (processes .get (j ).getArrivalTime () > processes .get (j + 1 ).getArrivalTime ()) {
35- temp = processes .get (j );
36- processes .set (j , processes .get (j + 1 ));
37- processes .set (j + 1 , temp );
38- }
39- }
40- }
40+ sortProcessesByArrivalTime (processes );
4141 }
4242
4343 /**
0 commit comments