Hallo Leute bin gerade dabei Quicksort zu verstehen jedoch macht mir dieser Teil zu schaffen. Ich weiß nicht in welcher Reihenfolge die Methoden in quicksort aufgerufen werden. Das Array ist danach sortiert also stimmt es wohl. Kann mir bitte wer erklären wie das funktioniert? Ich muss es verstehen!
LG
Code:
public static void quicksort(Integer [] a,int p,int r){
if(p<r){
int q = partition(a,p,r); //In welcher Reihenfolge?
quicksort(a,p,q-1); //In welcher Reihenfolge?
quicksort(a,q+1,r); //In welcher Reihenfolge?
}
}
public static int partition(Integer [] a,int p,int r){
int x=a[r];
int i=p-1;
for(int j=p; j<r; j++){
if(a[j].compareTo(x)<=0){
i=i+1;
swap(a,i,j);
}}
swap(a,i+1,r);
return i+1;
}
LG