PROCEDURE { shell } Sort
          (VAR   A: Ary;
                 N: Integer);
 { Shell-Metzner Sort }
 { Adapted from Programming in Pascal,
     P. Grogono, Addison-Wesley, 1980 }
 { From Borland Pascal Programs for Scientists and Engineers }
 { by Alan R. Miller, Copyright C 1993, SYBEX Inc }

VAR
  Done: Boolean;
  Jump, I, J: Integer;

BEGIN
  Jump := N;
  WHILE Jump > 1 DO
    BEGIN
      Jump := Jump DIV 2;
      REPEAT
        Done := True;
        FOR J := 1 TO N - Jump DO
          BEGIN
            I := J + Jump;
            IF A[J] > A[I] THEN
              BEGIN
                Swap(A[J], A[I]);
                Done := False
              END { if }
          END     { FOR }
      UNTIL Done
    END           { WHILE }
END;              { Sort }