【发布时间】:2011-05-02 23:17:34
【问题描述】:
TimSort 是一种在 Java 7 中默认用于排序的算法。
我找到了这个来源,但我不明白要调用哪个方法,因为它们都是私有的。 有人能理解吗?谢谢。
【问题讨论】:
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) {
...
}
从我上次发表评论的时间来看,这用了不到 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>
【讨论】:
public 并更改它所在的包吗?
TimSort.sort(myArray,myComparator);跨度>