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 >
Commodore BASIC  |  2022-10-26  |  558b  |  22 lines

  1. 100 dim f%(1000),l%(50),r%(50)
  2. 105 input"[193]nzahl der [197]lemente:";n%
  3. 110 print"[198]eld fuellen...  ";:t=ti
  4. 130 fori=1ton%:f%(i)=rnd(1)*32000:next
  5. 140 t=ti-t:printt/60"sec"
  6. 160 print"[198]eld sortieren... ";:t=ti
  7. 180 l%(1)=1:r%(1)=n%:t%=0:gosub500
  8. 190 t=ti-t:printt/60"sec"
  9. 220 goto105
  10. 230 :
  11. 500 t%=t%+1:ifl%(t%)>=r%(t%)then600
  12. 510 l%=l%(t%):r%=r%(t%):v%=f%((l%+r%)/2)
  13. 520 ifl%>r%then580
  14. 530 iff%(l%)<v%thenl%=l%+1:goto530
  15. 540 iff%(r%)>v%thenr%=r%-1:goto540
  16. 550 ifl%>r%then580
  17. 560 h%=f%(l%):f%(l%)=f%(r%):f%(r%)=h%
  18. 570 l%=l%+1:r%=r%-1:goto520
  19. 580 r%(t%+1)=r%:l%(t%+1)=l%(t%):gosub500
  20. 590 l%(t%+1)=l%:r%(t%+1)=r%(t%):gosub500
  21. 600 t%=t%-1:return
  22.