TimSort是一种在Java7中默认使用的排序算法。
我找到了这个源码,但我不知道该调用哪个方法,因为它们都是私有的。有人能理解吗?谢谢。
http://cr.openjdk.java.net/~martin/webrevs/openjdk7/timsort/raw_files/new/src/share/classes/java/util/TimSort.java
发布于 2011-05-03 07:20:09
你不会给任何东西打电话。
它有对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) {
...
}根据我上一条评论的时间判断,这花了不到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>https://stackoverflow.com/questions/5863509
复制相似问题