In practice, we often have to implement some of the more bizarre sort.
For example, in a group of [1,3,5,8,4,6,5], keep the original order unchanged, in the order of size. and establish a mapping relationship. (after sorting, use O (1) complexity to query the position of the first large number in the original array)
such as this
Index 0 1 2 3 4 5 6
Arr 1 3 5 8 4 6 5
Sort 6 5 2 0 4 1 3
For the algorithm party, this time can hand tear a fast platoon or merge and so on. (But if it's in the game, it's not the time.)
Wow, we have to make the most of the JDK.
Refers to this method of Arrays.sort (t[] A, comparator< Super t> C)).
Here is an example ... package sorts;
Import Java.util.Arrays;
Import Java.util.Comparator;
public class Arraysorttest {static class array_test{int be_sort;
Public array_test (int be_sort) {this.be_sort = Be_sort;
} public static void Main (string[] args) {int[] arr_test = {10,2,6,9,60,47,8,5,6,1};
array_test[] arr = new Array_test[arr_test.length];
for (int i = 0; I<arr.length i++) {Arr[i] = new Array_test (arr_test[i)); } arrays.sort (arr, new comparator<array_test> () {public int compare (Array_test O1, array_test o
2) {return o1.be_sort-o2.be_sort;
}
});
System.out.print ("[");
for (int i = 0; i<arr.length-1 i++) {System.out.print (arr[i].be_sort+ ",");
} System.out.print (Arr[arr.length-1].be_sort); System.out.printlN ("]");
}
}