home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
64'er Special 24
/
64er_Magazin_Sonderheft_24_19xx_Markt__Technik_de_Side_B.d64
/
quicksort
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-10-26
|
558b
|
22 lines
100 dim f%(1000),l%(50),r%(50)
105 input"[193]nzahl der [197]lemente:";n%
110 print"[198]eld fuellen... ";:t=ti
130 fori=1ton%:f%(i)=rnd(1)*32000:next
140 t=ti-t:printt/60"sec"
160 print"[198]eld sortieren... ";:t=ti
180 l%(1)=1:r%(1)=n%:t%=0:gosub500
190 t=ti-t:printt/60"sec"
220 goto105
230 :
500 t%=t%+1:ifl%(t%)>=r%(t%)then600
510 l%=l%(t%):r%=r%(t%):v%=f%((l%+r%)/2)
520 ifl%>r%then580
530 iff%(l%)<v%thenl%=l%+1:goto530
540 iff%(r%)>v%thenr%=r%-1:goto540
550 ifl%>r%then580
560 h%=f%(l%):f%(l%)=f%(r%):f%(r%)=h%
570 l%=l%+1:r%=r%-1:goto520
580 r%(t%+1)=r%:l%(t%+1)=l%(t%):gosub500
590 l%(t%+1)=l%:r%(t%+1)=r%(t%):gosub500
600 t%=t%-1:return