home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / sigmv024.ark / SHELL.LIB < prev    next >
Encoding:
Text File  |  1984-04-29  |  750 b   |  35 lines

  1. PROCEDURE Shellsort(VAR A : ScalarTyp;
  2.             n : INDEX);
  3. {
  4. The array A[1..n] is sorted in ascending order. The method is that
  5. of D.A. Shell, (A high-speed sorting procedure, Comm. ACM 2 (1959),
  6. 30-32) with subsequences chosen as suggested by T.N. Hibberd.
  7. }
  8. VAR
  9.   i, j, k, m    : integer;
  10.   done         : BOOLEAN;
  11.   temp        : SCALAR;
  12. begin (*$C-,M-,F-*)
  13.   m := n;
  14.   While m <> 0 do
  15.     begin
  16.       m := m DIV 2;
  17.       k := n - m;
  18.       for j:=1 to k do
  19.     begin
  20.       i := j;
  21.       done := FALSE;
  22.       repeat
  23.         if A[i+m] >= A[i] then
  24.           done := TRUE
  25.         else
  26.           begin
  27.         temp := A[i]; A[i] := A[i+m]; A[i+m] := temp;
  28.         i := i - m;
  29.           end;
  30.       until (i<1) OR ( done );
  31.     end{for j};
  32.     end{While};
  33. end;{Shellsort}{$C+,M+,F+}
  34.  
  35.