8-Bit Software Online Conversion
:0.B.TWOBUBS - Listing
10REM "TWOBUBS"
20REM Bubble Sort
30REM Auto Shrink
40REM Two Way
50:
60MODE7:VDU23;8202;0;0;0;
70@%=&50506
80ONERRORREPORT:PRINT" at line ";ERL:
END
90pass%=0
100size%=20
110max%=40
120seed%=1
130DIMA%(size%)
140PROCrandomize
150PROCbubble`sort
160PRINTCHR$(11)+" Sorted."
170END
180:
190DEFPROCrandomize
200seed%=RND(-seed%)
210FOR loop%=0 TO size%
220A%(loop%)=RND(max%)
230NEXT loop%
240PROCshowdata
250ENDPROC
260:
270DEFPROCshowdata
280CLS:PRINT" Bubble sort routine."'"
Pass number ";pass%;
290IF pass%=0 THEN PRINT" Initial stat
e." ELSE PRINT
300FOR loop%=0 TO size%
310PRINTA%(loop%)
320NEXT loop%
330PRINT" <SPACE>"
340REPEAT:UNTIL GET=32
350ENDPROC
360:
370DEFPROCbubble`sort
380low%=0:high%=size%
390REPEAT
400flag=FALSE
410pass%=pass%+1
420FOR loop%=low% TO high%-1
430IF A%(loop%)<A%(loop%+1) THEN swap%
=A%(loop%):A%(loop%)=A%(loop%+1):A%(loop
%+1)=swap%:flag=TRUE
440NEXT loop%
450high%=high%-1
460PROCshowdata
470pass%=pass%+1
480FOR loop%=high% TO low%+1 STEP -1
490IF A%(loop%)>A%(loop%-1) THEN swap%
=A%(loop%):A%(loop%)=A%(loop%-1):A%(loop
%-1)=swap%:flag=TRUE
500NEXT loop%
510low%=low%+1
520PROCshowdata
530UNTIL flag=FALSE
540ENDPROC