Sortierroutine für QuickSort
static void sort(double[] liste) {
quicksort(liste, 0, liste.length - 1);
}
static void quicksort(double[] a, int oben, int unten) {
int high = oben;
int low = unten;
double x = a[(high+low)/2]; // "mittleres" Element
// Aufteilen
while (high <= low) {
while (a[high] < x) { // suche großes Element bei den Kleinen
high++;
}
while (a[low] > x) { // suche kleines Element bei den Großen
low--;
}
if (high <= low) {
vertausche(a, high, low);
high++;
low--;
}
}
// Rekursion
if (oben < low) { // Abbruchbedingung
quicksort(a, oben, low);
}
if (high < unten) { // Abbruchbedingung
quicksort(a, high, unten);
}
}
static void vertausche(double[] a, int i, int j) {
// vertausche a[i] und a[j]
double temp = a[i];
a[i] = a[j];
a[j] = temp;
}