Typunabhängige Sortierprozedur

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

BubbleSort2.om
PROCEDURE Sort(gt: GreaterThanProc;
               exchange: ExchangeProc;
               nofitems: INTEGER);
   VAR
      bound: INTEGER;
         (* items[0] .. items[bound] are possibly unsorted;
            items[bound+1] .. items[nofitems-1] are sorted
            and at their final positions
         *)
      t: INTEGER;
         (* highest t where items[t] is possibly
            not yet sorted
         *)
      j: INTEGER;
         (* index of items *)
BEGIN
   bound := nofitems - 1;
   REPEAT
      (* B2 *)
      j := 0; t := 0;
      WHILE j < bound DO
         (* B3 *)
         IF gt(j, j+1) THEN
            exchange(j, j+1);
            t := j;
         END;
         INC(j);
      END;
      (* B4 *)
      bound := t;
   UNTIL bound = 0;
END Sort;

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