Sortierprozedur

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

BubbleSort.om
PROCEDURE Sort(VAR items: Items; 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 *)
      item: Item;
         (* temporary variable for swapping *)
BEGIN
   bound := nofitems - 1; (* B1 *)
   REPEAT
      (* B2 *)
      j := 0; t := 0;
      WHILE j < bound DO
         (* B3 *)
         IF items[j] > items[j+1] THEN
            item := items[j];
            items[j] := items[j+1];
            items[j+1] := item;
            t := j;
         END;
         INC(j);
      END;
      bound := t; (* B4 *)
   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