2011-05-02 127 views

回答

5

你什么也别打。

它有排序方法,包装私人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分钟的事:

And th e结果:

C:\Documents and Settings\glowcoder\My Documents>java SortTest 
Time for default: 4094ms 
Time for timsort: 3813ms 

C:\Documents and Settings\glowcoder\My Documents> 
+0

+1你又找到了我 – MByD 2011-05-02 23:24:11

+0

该死。你知道蒂姆排序在Java中的任何“完整”来源吗?我想我不能调用该方法,因为我们不在Java 7中。= x谢谢。 – Seva 2011-05-02 23:25:03

+1

@Seva你有没有特别需要打电话给TimSort?而且,是否有任何东西阻止你复制/粘贴并制作一个或两个“public”方法并更改它所在的包? – corsiKa 2011-05-02 23:27:02

相关问题