home *** CD-ROM | disk | FTP | other *** search
/ Big Blue Disk 17 / bbd17.zip / SHELLC.CHN (.txt) < prev    next >
Turbo Pascal Chain module  |  1987-12-23  |  6KB  |  52 lines

  1.   Compares: 
  2.      Swaps: 
  3. Assignments 
  4.  END OF DEMO. ! 
  5. sortdemo.chn
  6. %Enter a speed from 1 to 9 (1=slowest)
  7. %or 0 to single step thru program     
  8.  Press spacebar to continue... 
  9.  Press ESC to quit...          
  10. ' Press 1-9 to change speeds, 0 to pause
  11. Bad variable number.
  12. (----------------------------------------
  13. '---------------------------------------
  14. StageNo
  15.     StageOver
  16. Distance
  17. @Press  Space to continue, ESC to quit, 0-9 to change speeds, or 
  18.  to scroll.
  19. PROCEDURE ShellSort(
  20.   VAR L  { List to be sorted }
  21.     :List;
  22. &  N      { No. of items to be sorted }
  23.     :INTEGER
  24.    );
  25. #  Distance, StageNo, Loc : INTEGER;
  26.   StageOver: BOOLEAN;
  27. %PROCEDURE Swap( VAR X, Y : INTEGER );
  28. VAR Temp:INTEGER;
  29. BEGIN
  30.   Temp := X;
  31.       X := Y;
  32.   Y := Temp
  33.  BEGIN              { ShellSort }
  34.   Distance := N DIV 2;
  35.   WHILE Distance > 0  DO
  36.         BEGIN
  37. (      FOR StageNo := Distance TO N-1  DO
  38.         BEGIN
  39.           StageOver := False;
  40.           Loc := StageNo+1;
  41. 5          WHILE (Loc-Distance>0) AND NOT StageOver DO
  42.             BEGIN
  43. )              IF L[Loc] < L[Loc-Distance]
  44. 4                 THEN Swap( L[Loc],L[Loc-Distance] )
  45. (                 ELSE StageOver := True;
  46. #              Loc := Loc - Distance
  47.             END
  48.         END;
  49.        Distance := Distance DIV 2
  50.     END
  51. END;              { ShellSort }
  52.