ala*_*a27 1 java sorting timsort
TimSort是一种算法,默认情况下将在Java 7中用于排序.
我发现了这个来源,但我不明白要调用哪种方法,因为它们都是私有的.谁能理解?谢谢.
你什么都不打电话.
它具有包私有的排序方法java.util.当你调用Arrays.sort()函数或类似函数时,你让它调用它们.
评论表明了这一点:
/*
* The next two methods (which are package private and static) constitute
* the entire API of this class. Each of these methods obeys the contract
* of the public method with the same signature in java.util.Arrays.
*/
static <T> void sort(T[] a, Comparator<? super T> c) {
sort(a, 0, a.length, c);
}
static <T> void sort(T[] a, int lo, int hi, Comparator<? super T> c) {
...
}
Run Code Online (Sandbox Code Playgroud)
从我上次评论的时间来看,这花了不到15分钟的时间:
结果如下:
C:\Documents and Settings\glowcoder\My Documents>java SortTest
Time for default: 4094ms
Time for timsort: 3813ms
C:\Documents and Settings\glowcoder\My Documents>
Run Code Online (Sandbox Code Playgroud)