Hallo zusammen,
ich hab folgendes Problem!
Ich muss eine Liste mit QuickSort sortieren. Die Liste die Ich anlege wird sortiert bis zu 5 Elementen, sobald ich ein 6 Element hinzufüge hängt sich der Quicksort auf :noe:
vielleicht kann mir da jemand nen Tipp geben was ich da noch ändern kann.
Code:
ich hab folgendes Problem!
Ich muss eine Liste mit QuickSort sortieren. Die Liste die Ich anlege wird sortiert bis zu 5 Elementen, sobald ich ein 6 Element hinzufüge hängt sich der Quicksort auf :noe:
vielleicht kann mir da jemand nen Tipp geben was ich da noch ändern kann.
Code:
Java:
public class ListeAlgo {
public static <T> void quickSort(Liste<T> liste, java.util.Comparator<T> comp){
System.out.println("bin in erster Methode");
quickSort(liste,comp,0,liste.size());
}
public static <T> void quickSort(Liste<T>liste, java.util.Comparator<T> comp, int il, int ir){
System.out.println("bin in zweiter methode");
if((ir-il)<=1){
return;
}
System.out.println("bin vor ipiv");
int ipiv=(il+ir)/2;
T pivot= liste.get(ipiv);
System.out.println("bin nach zuweisung T pivot");
liste.swap(ipiv, ir-1);
int l=il;
int r=ir-2;
do{
while(comp.compare(liste.get(l),pivot)<0){
l++;}
while(l<r&&comp.compare(liste.get(r), pivot)>0){
r--;}
}while(l<r);
ipiv= l;
liste.swap(ipiv,ir-1);
quickSort(liste,comp, il,ipiv);
quickSort(liste,comp, ipiv+1,ir);
}
public static void main(String[] args) {
AbstractListe<Integer> ws = new DVLListe<Integer>();
IntegerComp com = new IntegerComp();
ws.add(0,5);
ws.add(1,2);
ws.add(2,1);
ws.add(3,4);
ws.add(4,3);
//ws.add(5,6);
quickSort(ws,com);
while(!ws.isEmpty()){
System.out.print(ws.getFirst()+", ");
ws.removeFirst();
}
}
}