home *** CD-ROM | disk | FTP | other *** search
- 10 dim w$(50):print"[147]":menu=12:poke53272,21
- 20 a$="loading words. please wait...":gosub430
- 30 poke214,16:print:print"[152]"spc(20-len(a$)/2)a$
- 40 open2,8,2,"words":fori=1to50:input#2,w$(i):next:close2
- 50 poke198,0:restore:gosub430:fory=1to11:reada$:gosub400:next
- 60 geta$:ifa$<"1"ora$>"5"then60
- 70 onval(a$)gosub110,150,260,80,740:goto50
- 80 print"[147]"
- 90 fori=1to50:printw$(i),:wait197,64:next
- 100 print:print"any key to continue ":poke198,0:wait198,1:print"[147]":return
- 110 rem============shuffle===========
- 120 a$="shuffling":gosub430:poke214,16:print:print"[152]"spc(20-len(a$)/2)a$
- 130 forj=1to50:j%=rnd(ti)*50+1
- 140 t$=w$(j):w$(j)=w$(j%):w$(j%)=t$:next:return
- 150 rem========bubble sort=======
- 160 a$="bubble sorting":gosub430:poke214,16:print:print"[152]"spc(20-len(a$)/2)a$
- 170 c=0:ti$="000000":forp=1to51:fors=1to49
- 180 ifw$(s)>w$(s+1)thenc=c+1:a$=w$(s):w$(s)=w$(s+1):w$(s+1)=a$
- 190 next:poke53280,p:next
- 200 rem =========bubble sort end=====
- 210 tb$=ti$:gosub430:y=13:a$="time:"+str$(val(tb$)):gosub380
- 220 a$=str$(c)+" total switches"
- 230 gosub380:a$="press a key...":gosub380:poke198,0:wait198,1:poke198,0
- 240 restore:fori=1to12:read a$:next:y=11:fori=1to11:reada$:gosub380:next
- 250 poke198,0:wait198,1:return
- 260 rem=====quick sort=======
- 270 a$="quick sorting":gosub430:poke214,16:print:print"[152]"spc(20-len(a$)/2)a$
- 280 c=0:ti$="000000":b=1:q=50:forp=1to50/2:a$="":b$="zz":fors=bto50-p:c$=w$(s)
- 290 ifc$>a$thenifc$>w$(q)thenc=c+1:a$=w$(q):w$(q)=c$:w$(s)=a$:goto310
- 300 ifc$<b$thenifc$<w$(b)thenc=c+1:b$=w$(b):w$(b)=c$:w$(s)=b$
- 310 next:q=q-1:b=b+1:poke53280,p:next
- 320 rem=======end quick sort========
- 330 tp$=ti$:gosub430:y=13:a$="time:"+str$(val(ti$)):gosub380
- 340 a$=str$(c)+" total switches"
- 350 gosub380:a$="press a key...":gosub380:poke198,0:wait198,1:poke198,0
- 360 restore:fori=1to23:read a$:next:y=11:fori=1to11:reada$:gosub380:next
- 370 poke198,0:wait198,1:return
- 380 poke214,y:print:print"[152]"a$:y=y+1:return
- 390 stop
- 400 rem main print
- 410 poke214,10+y:print:print"[152]"a$"":return
- 420 stop
- 430 poke53280,0:poke53281,0
- 440 print"[146] [159]**** faster sorting ****"
- 450 print" [155][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][152]"
- 460 fori=1to11:print" ":next
- 470 print" [151][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185]";
- 480 print"[159]";:return
- 490 data,this program will sort 50 words
- 500 data using the old bubble sort code and
- 510 data a version of the quick sort.,
- 520 data,1. to shuffle words,2. bubble sort
- 530 data3. quick sort,4. view words
- 540 data5. quit
- 550 data,the bubble sort will switch item
- 560 data1 with 2 if 1 is of greater value.
- 570 dataif item 2 > item 3 then they are
- 580 dataswitched next. this goes on for
- 590 data"51 passes. "
- 600 data100 items need 101 passes.
- 610 datathis isn't very efficient since
- 620 datathe sort may have to move the same
- 630 data same item more than once.,,press a key...
- 640 datathe quick sort finds the two most
- 650 data extreme values and places them.
- 660 data after this it does less work because
- 670 data it shaves its limits of concern.
- 680 datathe top and bottom ranges are closed
- 690 data in. the list is sorted from the,outside in.,
- 700 you can increase the speed of this sort!
- 710 data basic can get the job done faster
- 720 dataif it juggles fewer bytes and,reads fewer instructions! (return)
- 730 printpeek(197):goto730
- 740 open15,8,15,"r0:hello connect=hello connect":input#15,er:close15
- 750 if er<>63 then print"[147]":end
- 760 a$="hello connect":q$=chr$(34)
- 770 print"[144][147]load"q$a$q$",8"
- 780 print"run":poke631,13:poke632,13:poke198,2:end
-