Permutationen III

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

Permutations.om
PROCEDURE GenPermutations(k, n: INTEGER; perm: Permutation);
   (* perm[0..k-1] is already fixed,
      generate all variants for perm[k..n-1]
   *)
   VAR
      nperm: Permutation;
      i, j: INTEGER;
BEGIN
   IF k = n THEN
      GenPermutation(perm, n);
   ELSE
      i := 1;
      WHILE i <= k+1 DO
         nperm := perm;
         j := 0;
         WHILE j < k DO
            IF nperm[j] >= i THEN
               INC(nperm[j]);
            END;
            INC(j);
         END;
         nperm[k] := i;
         GenPermutations(k + 1, n, nperm);
         INC(i);
      END;
   END;
END GenPermutations;

*Nachteil dieser Lösung: Die Permutationen werden 2x kopiert: Einmal bei der Parameterübergabe und einmal bei der Bestimmung jeder neuen Permutation.
 

 [Vorheriges Kapitel]  [Vorherige Seite]  [Inhaltsverzeichnis]  [Nächste Seite]  [Nächstes Kapitel]
Copyright © 1999, 2004 Andreas F. Borchert, in HTML konvertiert am 28.01.2005