8-Bit Software Online Conversion
:2.B.SELECT - Listing
10REM "B.SELECT"
20REM SELECTION SORT
30REM ALSO KNOWN AS EXCHANGE SORT
40:
50MODE7:VDU23;8202;0;0;0;
60@%=&50506
70ONERRORREPORT:PRINT" at line ";ERL:
END
80pass%=0
90size%=20
100max%=40
110seed%=1
120DIMA%(size%)
130PROCrandomize
140PROCselection`sort
150PRINTCHR$(11)+" Sorted."
160END
170:
180DEFPROCrandomize
190seed%=RND(-seed%)
200FOR loop%=0 TO size%
210A%(loop%)=RND(max%)
220NEXT loop%
230PROCshowdata
240ENDPROC
250:
260DEFPROCshowdata
270CLS:PRINT" Bubble sort routine."'"
Pass number ";pass%;
280IF pass%=0 THEN PRINT" Initial stat
e." ELSE PRINT
290FOR loop%=0 TO size%
300PRINTA%(loop%)
310NEXT loop%
320PRINT" <SPACE>"
330REPEAT:A=GET:UNTIL A=32
340ENDPROC
350:
360DEFPROCselection`sort
370counter%=size%
380REPEAT
390pass%=pass%+1
400minsofar%=max%
410FOR loop%=0 TO counter%
420IF A%(loop%)<minsofar% THEN positio
n%=loop%:minsofar%=A%(loop%)
430NEXT loop%
440swap%=A%(counter%):A%(counter%)=A%(
position%):A%(position%)=swap%
450counter%=counter%-1
460PROCshowdata
470UNTIL (minsofar%=max%)
480ENDPROC