8-Bit Software Online Conversion
:0.B.COUNT1 - Listing
10REM COUNTED SORT
20REM BY HUGH STUART WILLIAMS 1990
40MODE7:VDU23;8202;0;0;0;
50@%=&50506
60ONERRORREPORT:PRINT" at line ";ERL:
END
70size%=15
80max%=255
90seed%=1
100DIM items%(size%)
110DIM count%(max%)
120DIM position%(size%)
130PROCclear`totals
140PROCrandomize
150PROCshow`data
160PROCcounted`sort
170PROCshow`data
180END
190:
200DEFPROCclear`totals
210FOR loop%=0 TO max%
220count%(loop%)=0
230NEXT loop%
240ENDPROC
250:
260DEFPROCrandomize
270seed%=RND(-seed%)
280FOR loop%=0 TO size%
290items%(loop%)=RND(max%+1)-1
300position%(loop%)=0
310NEXT loop%
320ENDPROC
330:
340DEFPROCshow`data
350CLS:PRINT'" Counted sort routine. "
'
360PRINT" Initial Position in sorted
"
370PRINT" List List"
380FOR loop%=0 TO size%
390PRINTitems%(loop%),position%(loop%)
400NEXT loop%
410PRINT" <SPACE> "
420REPEAT:UNTIL GET=32
430ENDPROC
440:
450DEFPROCcounted`sort
460T%=TIME
470FOR loop%=0 TO size%
480count%(items%(loop%))=count%(items%
(loop%))+1
490NEXT loop%
500:
510FOR loop%=1 TO max%
520count%(loop%)=count%(loop%)+count%(
loop%-1)
530NEXT loop%
540:
550FOR loop%=size% TO 0 STEP-1
560position%(loop%)=count%(items%(loop
%))-1
570count%(items%(loop%))=count%(items%
(loop%))-1
580NEXT loop%
590PRINT"Sort time : ";(TIME-T%)/100;"
secs."
600PRINT" <SPACE>":A=GET
610ENDPROC