Präsentation der Arbeitsweise des Sortieralgorithmus Quicksort
10 11 9 1 6 2 5 3 7 8 4 i=0 j=11 wert=0 wert ist das partitionierende Element. Der grüne Zeiger wandert von links nach rechts. Er bleibt stehen, sobald er eine Zahl gefunden hat, die größer als wert ist. Der rote Zeiger wandert von rechts nach links. Er bleibt stehen, sobald er eine Zahl gefunden hat, die kleiner oder gleich wert ist. Dann werden die Zahlen an den Positionen des grünen und roten Zeigers miteinander vertauscht – größere Zahlen als wert wandern damit von links nach rechts, kleinere Zahlen als wert wandern damit von rechts nach links. Quicksort
10 11 9 1 6 2 5 3 7 8 4 i=0 j=10 wert=0 Quicksort
10 11 9 1 6 2 5 3 7 8 4 i=0 j=9 wert=0 Quicksort
10 11 9 1 6 2 5 3 7 8 4 i=0 j=8 wert=0 Quicksort
10 11 9 1 6 2 5 3 7 8 4 i=0 j=7 wert=0 Quicksort
10 11 9 1 6 2 5 3 7 8 4 i=0 j=6 wert=0 Quicksort
10 11 9 1 6 2 5 3 7 8 4 i=0 j=5 wert=0 0 und 10 tauschen nun die Plätze – große Zahlen nach rechts, kleine Zahlen nach links. Quicksort
11 9 1 6 10 2 5 3 7 8 4 i=1 j=4 wert=0 Quicksort
11 9 1 6 10 2 5 3 7 8 4 i=1 j=3 wert=0 Quicksort
11 9 1 6 10 2 5 3 7 8 4 i=1 j=2 wert=0 Quicksort
11 9 1 6 10 2 5 3 7 8 4 i=1 j=1 wert=0 Quicksort
11 9 1 6 10 2 5 3 7 8 4 j=0 i=1 wert=0 Sobald die Zeiger sich überlaufen, ist ein Durchlauf fertig. Neu partitionieren, wobei es nur einen rechten Teil gibt. Quicksort
11 9 1 6 10 2 5 3 7 8 4 i=1 j=11 wert=2 Der grüne Zeiger wandert von links nach rechts. Er bleibt stehen, sobald er eine Zahl gefunden hat, die größer als wert ist. Der rote Zeiger wandert von rechts nach links. Er bleibt stehen, sobald er eine Zahl gefunden hat, die kleiner oder gleich wert ist. Dann werden die Zahlen an den Positionen des grünen und roten Zeigers miteinander vertauscht – größere Zahlen als wert wandern damit von links nach rechts, kleinere Zahlen als wert wandern damit von rechts nach links. Quicksort
11 9 1 6 10 2 5 3 7 8 4 i=1 j=10 wert=2 Quicksort
11 9 1 6 10 2 5 3 7 8 4 i=1 j=9 wert=2 Quicksort
11 9 1 6 10 2 5 3 7 8 4 i=1 j=8 wert=2 Quicksort
11 9 1 6 10 2 5 3 7 8 4 i=1 j=7 wert=2 Quicksort
11 9 1 6 10 2 5 3 7 8 4 i=1 j=6 wert=2 2 und 11 tauschen nun die Plätze – große Zahlen nach rechts, kleine Zahlen nach links. Quicksort
2 9 1 6 10 11 5 3 7 8 4 i=2 j=5 wert=2 Quicksort
2 9 1 6 10 11 5 3 7 8 4 i=2 j=4 wert=2 Quicksort
2 9 1 6 10 11 5 3 7 8 4 i=2 j=3 wert=2 Quicksort
2 1 9 6 10 11 5 3 7 8 4 j=2 i=3 wert=2 Neu partitionieren: linker Teil von 1 bis 2 mit wert=2, rechter Teil von 3 bis 11 mit wert=5. Quicksort
2 1 9 6 10 11 5 3 7 8 4 i=1 j=2 i=3 j=11 wert=2 wert=5 Quicksort
1 2 4 6 10 11 5 3 7 8 9 j=1 i=2 i=4 j=10 wert=2 wert=5 Neu partitionieren ist links nicht mehr möglich. Quicksort
1 2 4 6 10 11 5 3 7 8 9 i=4 j=9 wert=5 Quicksort
1 2 4 6 10 11 5 3 7 8 9 i=4 j=8 wert=5 Quicksort
1 2 4 3 10 11 5 6 7 8 9 i=5 j=7 wert=5 Quicksort
1 2 4 3 5 11 10 6 7 8 9 i=6 j=6 wert=5 Quicksort
1 2 4 3 5 11 10 6 7 8 9 j=5 i=6 wert=5 Neu partitionieren: linker Teil von 3 bis 5 mit wert=3, rechter Teil von 6 bis 11 mit wert=6. Quicksort
1 2 4 3 5 11 10 6 7 8 9 i=3 j=5 i=6 j=11 wert=3 wert=6 Quicksort
1 2 4 3 5 11 10 6 7 8 9 i=3 j=4 i=6 j=10 wert=3 wert=6 Quicksort
1 2 3 4 5 11 10 6 7 8 9 j=3 i=4 i=6 j=9 wert=3 wert=6 Neu partitionieren: Linke Seite: linker Teil nicht möglich, rechter Teil von 4 bis 5 mit wert=4. Rechte Seite läuft noch weiter. Quicksort
1 2 3 4 5 11 10 6 7 8 9 i=4 j=5 i=6 j=8 wert=4 wert=6 Quicksort
1 2 3 4 5 6 10 11 7 8 9 i=4 j=4 i=7 j=7 wert=4 wert=6 Quicksort
1 2 3 4 5 6 10 11 7 8 9 j=3 i=5 j=6 i=7 wert=4 wert=6 Neu partitionieren: beide linke Teile nicht möglich, rechter Teil von 7 bis 11 mit wert=7. Quicksort
1 2 3 4 5 6 10 11 7 8 9 i=7 j=11 wert=7 Neu partitionieren: beide linke Teile nicht möglich, rechter Teil von 7 bis 11 mit wert=7. Quicksort
1 2 3 4 5 6 10 11 7 8 9 i=7 j=10 wert=7 Quicksort
1 2 3 4 5 6 10 11 7 8 9 i=7 j=9 wert=7 Quicksort
1 2 3 4 5 6 7 11 10 8 9 i=8 j=8 wert=7 Quicksort
1 2 3 4 5 6 7 11 10 8 9 j=8 i=8 wert=7 Neu partitionieren: linker Teil nicht möglich, rechter Teil von 8 bis 11 mit wert=10. Quicksort
1 2 3 4 5 6 7 11 10 8 9 i=8 j=11 wert=10 Quicksort
1 2 3 4 5 6 7 9 10 8 11 i=9 j=10 wert=10 Quicksort
1 2 3 4 5 6 7 9 8 10 11 j=9 i=10 wert=10 Neu partitionieren: linker Teil von 8 bis 9 mit wert=9, rechter Teil von 10 bis 11 mit wert=10. Quicksort
1 2 3 4 5 6 7 9 8 10 11 i=8 j=9 i=10 j=11 wert=10 Quicksort
1 2 3 4 5 6 7 8 9 10 11 j=8 i=9 i=10 j=10 wert=10 Neu partitionieren ist links nicht mehr möglich. Quicksort
1 2 3 4 5 6 7 8 9 10 11 j=9 i=11 wert=10 Fertig! Quicksort