0

My Array has

P   B   A
---------
1  135  0
2  102  0
3  56   0
4  148  0
5  125  0
6  65   200 

This array is currently been sorted like this

3  56   0  
2  102  0  
5  125  0  
1  135  0  
4  148  0  
6  65  200  

with this current code

         Arrays.sort(x, new Comparator<int[]>() {
                public int compare(int[] o1, int[] o2) {
                    int ret = Integer.compare(o1[2], o2[2]);
                    // if the entries are equal at index 2, compare index 1
                    if (0 == ret) {
                        ret = Integer.compare(o1[1], o2[1]);
                    }
                    return (ret);
                }
            });

What I want to do is to order the rows of the array so it would look like this depending the sum of B compared with rows of A.

P   B   A
3  56   0  
2  102  0  
5  125  0 
6  65   200  <<-- this row was the one that alter 
1  135  0  
4  148  0  

So when we sum 56+102+125= 283 >200 now we get the smallest row next that it would be 6 65 200.

Im basicly tring to implement Shortest Process Next

Like this picture

This is the code that I tried

int whencount=0;
        ArrayList <Integer> m = new ArrayList<Integer>();


            for(int e=0; e<myArr.length; e++){

                whencount=whencount+myArr[e][1];
                for(int i=0; i<myArr.length; i++){

                 if(myArr[i][2]>=whencount && myArr[e][2]>=whencount){ 
                     System.out.println("Process executed "+myArr[e][0]);
                     m.add(myArr[e][0]);
                 }

                }

            }
Ifrahim Hernandez
  • 105
  • 1
  • 3
  • 10

0 Answers0