home *** CD-ROM | disk | FTP | other *** search
/ Big Blue Disk 17 / bbd17.zip / INSERTC.CHN (.txt) < prev    next >
Turbo Pascal Chain module  |  1987-12-03  |  6KB  |  46 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. @Press  Space to continue, ESC to quit, 0-9 to change speeds, or 
  17.  to scroll.
  18. PROCEDURE Insert(
  19.   VAR L  { List to be sorted }
  20.     :List;
  21. &  N      { No. of items to be sorted }
  22.     :INTEGER
  23.    );
  24.   StageNo, Loc : INTEGER;
  25.   StageOver: BOOLEAN;
  26. %PROCEDURE Swap( VAR X, Y : INTEGER );
  27. VAR Temp:INTEGER;
  28. BEGIN
  29.   Temp := X;
  30.       X := Y;
  31.   Y := Temp
  32. BEGIN              { Insert }
  33.   FOR StageNo := 1 TO N-1 DO
  34.         BEGIN
  35.       StageOver := False;
  36.       Loc := StageNo+1;
  37. (      WHILE (Loc>1) AND NOT StageOver DO
  38.         BEGIN
  39.           IF L[Loc] < L[Loc-1]
  40. &            THEN Swap(L[Loc],L[Loc-1])
  41. #            ELSE StageOver := True;
  42.           Loc := Loc - 1
  43.         END
  44.     END
  45. END;              { Insert }
  46.