2016-04-29 17 views
0

2番目の要素に基づいて2dのArraylistをソートしようとしています。2つの要素に基づいて2dのarraylistをソート

だから私のArrayListのは

[[1, 4, 0], [2, 5, 2], [3, 5, 3], [4, 3, 6]]

のように見えると私はそれがあまりにもこれはこれは私がこれまで使ってきたものである私のArrayList

ArrayList<ArrayList<Integer>> processes = new ArrayList<>(); 

あるこの

[[4, 3, 6], [1, 4, 0], [2, 5, 2], [3, 5, 3]]

のようになりたいです選択ソート

int smallInt; 
int j; 
int smallIntIndex; 
for(int i = 1; i<=processes.size();i++){ 
    smallInt = processes.get(i-1).get(1); 
    smallIntIndex = i-1; 
    for(j=i;j<processes.size();j++){ 
     if(processes.get(j).get(1)==smallInt){ 
      //not exactly sure what goes in here 
     }else if(processes.get(j).get(1)<smallInt){ 
      smallInt = processes.get(j).get(1); 
      smallIntIndex = j; 
     } 
    } 
    ArrayList<Integer> temp = processes.get(smallIntIndex); 
    processes.set(smallIntIndex,processes.get(i-1)); 
    processes.set(i-1,temp); 
} 
+0

[[4,3,6]、[1,4,0​​]、[2,5,2]、[3,5,3]]はどのようにソートされていますか? – robotlos

+0

第1要素(ネストされた配列リストの第1インデックス)に基づいてソートされます。 –

+0

'processes.sort(firstElement、secondElement) - > Integer.compare(firstElement.get(1)、secondElement.get(1)); ' – Palle

答えて

0

ラベル(例: 1または2または3 - 最初/ 2番目/ 3番目のエントリ)を制限されたセット(たとえば、数字のみ)から削除しますか? もしそうなら(私が思う)、Radix sortを適用して並べ替えることができます。

関連する問題