8-Bit Software Online Conversion
:2.B.SHELL - Listing
10REM "B.SHELL"
20REM SHELL SORT
30REM HARD TO UNDERSTAND
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
140PROCshell`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" Shell 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:
360DEFPROCshell`sort
370counter%=size%
380REPEAT
390pass%=pass%+1
400counter%=counter% DIV 2
410FOR loop%=0 TO size%-counter%
420low%=loop%
430high%=counter%+loop%
440REPEAT
450flag=FALSE
460IF A%(high%)>A%(low%) THEN swap%=A%
(low%):A%(low%)=A%(high%):A%(high%)=swap
%:high%=low%:low%=low%-counter%:flag=TRU
E
470UNTIL (flag=FALSE) OR (low%<=0)
480NEXT loop%
490PROCshowdata
500UNTIL counter%<=0
510ENDPROC