custom sorting a java array

前端 未结 4 934
长情又很酷
长情又很酷 2021-01-06 03:41

I have an [] that has some numbers (distances from some point).
I want to create an array of indexes into the first array where the indexes are sorted by the distance.

4条回答
  •  广开言路
    2021-01-06 04:18

    I did try it now and it works! :)

    double[] dist= {3.2, 1.4, 7.3, 2.2, 9.1}; // your array
    int[] sortedIndexes= new int[dist.length]; // your array
    
    double[] temp = dist.clone(); // clone the array
    Arrays.sort(temp); // Use native array sort function
    
    for(int i = 0; i

提交回复
热议问题