Frage

Timsort ist ein Algorithmus, der in Java 7 standardmäßig zum Sortieren verwendet wird.

Ich habe diese Quelle gefunden, aber ich verstehe nicht, welche Methode ich aufrufen soll, da alle privat sind. Kann jemand verstehen? Vielen Dank.

http://cr.openjdk.java.net/~martin/webrevs/openjdk7/timsort/raw_files/new/src/share/classes/java/util/timsort.java

War es hilfreich?

Lösung

Sie rufen nichts an.

Es verfügt java.util. Sie lassen es sie anrufen, wenn Sie das anrufen Arrays.sort() Funktion oder so etwas.

Dies wird durch den Kommentar deutlich:

/*
 * 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) {
    ...
}

Nach meinem letzten Kommentar zu urteilen, dauerte dies weniger als 15 Minuten:

Und das Ergebnis:

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

C:\Documents and Settings\glowcoder\My Documents>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top