home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Big Blue Disk 17
/
bbd17.zip
/
INSERTC.CHN
(
.txt
)
< prev
next >
Wrap
Turbo Pascal Chain module
|
1987-12-03
|
6KB
|
46 lines
Compares:
Swaps:
Assignments
END OF DEMO. !
sortdemo.chn
%Enter a speed from 1 to 9 (1=slowest)
%or 0 to single step thru program
Press spacebar to continue...
Press ESC to quit...
' Press 1-9 to change speeds, 0 to pause
Bad variable number.
(----------------------------------------
'---------------------------------------
StageNo
StageOver
@Press Space to continue, ESC to quit, 0-9 to change speeds, or
to scroll.
PROCEDURE Insert(
VAR L { List to be sorted }
:List;
& N { No. of items to be sorted }
:INTEGER
);
StageNo, Loc : INTEGER;
StageOver: BOOLEAN;
%PROCEDURE Swap( VAR X, Y : INTEGER );
VAR Temp:INTEGER;
BEGIN
Temp := X;
X := Y;
Y := Temp
BEGIN { Insert }
FOR StageNo := 1 TO N-1 DO
BEGIN
StageOver := False;
Loc := StageNo+1;
( WHILE (Loc>1) AND NOT StageOver DO
BEGIN
IF L[Loc] < L[Loc-1]
& THEN Swap(L[Loc],L[Loc-1])
# ELSE StageOver := True;
Loc := Loc - 1
END
END
END; { Insert }