9
Quicksort nach Hoare

Quicksort nach Hoare. Liste von int-Werten 7675888604182774986 4975841608882777686

Embed Size (px)

Citation preview

Page 1: Quicksort nach Hoare. Liste von int-Werten 7675888604182774986 4975841608882777686

Quicksort

nach

Hoare

Page 2: Quicksort nach Hoare. Liste von int-Werten 7675888604182774986 4975841608882777686

Liste von int-Werten

76 7 58 88 60 41 82 77 49 86

49 7 58 41 60 88 82 77 76 86

Page 3: Quicksort nach Hoare. Liste von int-Werten 7675888604182774986 4975841608882777686

49 7 58 41 60 88 82 77 76 86

        60          

49 7 58 41   88 82 77 76 86

7 49 58 41   76 77 82 88 86

Page 4: Quicksort nach Hoare. Liste von int-Werten 7675888604182774986 4975841608882777686

        60          

49 7 58 41   88 82 77 76 86

7 49 58 41   76 77 82 88 86

7       60   77      

  49 58 41   76   82 88 86

  49 41 58   76   82 86 88

Page 5: Quicksort nach Hoare. Liste von int-Werten 7675888604182774986 4975841608882777686

7     58 60 76 77     88

  49  41         82 86  

   41 49         82 86

7       60   77      

  49 58 41   76   82 88 86

  49 41 58   76   82 86 88

Page 6: Quicksort nach Hoare. Liste von int-Werten 7675888604182774986 4975841608882777686

7     58 60 76 77     88

  49  41         82 86  

   41 49         82 86

7   49 58 60 76 77 82   88

  41             86  

   41             86

Page 7: Quicksort nach Hoare. Liste von int-Werten 7675888604182774986 4975841608882777686

7   49 58 60 76 77 82   88

  41             86  

   41             86

7 41 49 58 60 76 77 82 86 88

                   

               

Page 8: Quicksort nach Hoare. Liste von int-Werten 7675888604182774986 4975841608882777686

public static void quickSort(int[] liste){ int untereGrenze = 0; int obereGrenze = liste.length-1; quickSort(liste, untereGrenze,obereGrenze); }

Page 9: Quicksort nach Hoare. Liste von int-Werten 7675888604182774986 4975841608882777686

private static void quickSort(int[] liste, int untereGrenze, int obereGrenze) { int links = untereGrenze; int rechts = obereGrenze; int pivot = liste[((untereGrenze + obereGrenze) / 2)]; do { while (liste[links] < pivot) { links++; } while (pivot < liste[rechts]) { rechts--; } if (links <= rechts) { int tmp = liste[links]; liste[links] = liste[rechts]; liste[rechts] = tmp; links++; rechts--; } } while (links <= rechts); if (untereGrenze < rechts) liste = quickSort(liste, untereGrenze, rechts); if (links < obereGrenze) liste = quickSort(liste, links, obereGrenze); }