2011-05-02 125 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

相關問題