home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 December
/
simtel1292_SIMTEL_1292_Walnut_Creek.iso
/
msdos
/
pcmag
/
vol8n05.arc
/
SORT.BAS
< prev
next >
Wrap
BASIC Source File
|
1989-02-06
|
971b
|
40 lines
DEFINT A-Z
CLS
DIM Array(20) 'create and fill a test array
FOR X = 0 TO 20
Array(X) = RND(1) * 1000
PRINT Array(X)
NEXT
Done = -1 'this is required to initialize Sort
DO
PRINT "."; 'do anything you want here
GOSUB BSort
LOOP UNTIL Done
FOR X = 0 TO 20 'show that it was sorted correctly
LOCATE X + 1, 15
PRINT Array(X)
NEXT
END
BSort:
IF NOT Done GOTO MoreSort
Size = UBOUND(Array, 1) - 1
LoLimit = LBOUND(Array, 1)
Done = 0
FOR X = Size TO LoBound STEP -1
FOR Y = LoBound TO X
IF Array(Y) > Array(Y + 1) THEN
SWAP Array(Y), Array(Y + 1)
END IF
NEXT
RETURN 'exit after each pass
MoreSort:
NEXT
Done = -1
RETURN