How to find the permutation of a sort in Java

后端 未结 5 1161
攒了一身酷
攒了一身酷 2021-01-11 22:41

I want to sort an array and find the index of each element in the sorted order. So for instance if I run this on the array:

[3,2,4]

I\'d ge

5条回答
  •  滥情空心
    2021-01-11 23:22

    import java.io.*;
    
    public class Sample {
        public static void main(String[] args) {
            int[] data = {0, 3, 2, 4, 6, 5, 10};//case:range 0 - 10
            int i, rangeHigh = 10;
            int [] rank = new int[rangeHigh + 1];
            //counting sort
            for(i=0; i< data.length ;++i) ++rank[data[i]];
            for(i=1; i< rank.length;++i) rank[i] += rank[i-1];
            for(i=0;i

提交回复
热议问题