Quick-Sort Sortierprozedur

 [Vorheriges Kapitel]  [Vorherige Seite]  [Inhaltsverzeichnis]  [Nächste Seite]  [Nächstes Kapitel]

QuickSort.om
top := 0; (* initialize job stack *)
PushJob(0, nofitems-1);
WHILE FetchJob(first, last) DO
   (* sort all items with indices first..last *)
   IF first < last THEN
      (* select pivot element *)
      pivot := (first + last) DIV 2;
      (* divide ... *)
      i := first; j := last;
      REPEAT
         WHILE gt(pivot, i) DO
            INC(i);
         END;
         WHILE gt(j, pivot) DO
            DEC(j);
         END;
         IF i <= j THEN
            Exchange(i, j, pivot);
            INC(i); DEC(j);
         END;
      UNTIL i > j;
      (* ... and conquer *)
      PushJob(first, j);
      PushJob(i, last);
   END;
END;

 [Vorheriges Kapitel]  [Vorherige Seite]  [Inhaltsverzeichnis]  [Nächste Seite]  [Nächstes Kapitel]
Copyright © 2004, 2005 Andreas Borchert, in HTML konvertiert am 18.02.2005