home *** CD-ROM | disk | FTP | other *** search
- REM **********************************************************************
- REM ****************** Copyright Softbridge, Inc. ***********************
- REM **********************************************************************
-
- '---------------------------------------------------------------------------
- '-----------------------------Program Notes---------------------------------
- ' This program is an implementation of a recursive quicksort. It is a
- ' good program to run in debug mode. I usually open the 'calls' window
- ' in the debugger and then hit 'animate'.
- '---------------------------------------------------------------------------
-
-
- const max%=1000
-
- dim a(MAX) as double
- dim count as integer
-
-
- sub quicksort(l as integer, r as integer)
- dim v as double, t as double
- dim i as integer, j%
- if (r>l) then
- v=a(r) : i=l-1 : j=r : a(0) = v
- do
- do : i=i+1 : loop until a(i)>=v
- do : j=j-1 : loop until a(j)<=v
- t=a(i) : a(i)=a(j) : a(j)=t
- loop until (j<=i)
- a(j)=a(i) : a(i)= a(r) : a(r)=t
- call quicksort(l,i-1)
- call quicksort(i+1,r)
- end if
- end sub
-
- sub display
- for i%=1 to count
- print "i=", i, "a(i)=", a(i)
-
- next i
- end sub
-
- sub main
-
-
- count = val(command$)
- while (count = 0)
- count = val(inputbox("enter size of list"))
- wend
- t0 = timer
- for i=1 to count
- a(i) = rnd(0.5)
- next i
- call quicksort(1,count)
- t1 = timer
- msgbox "elapsed time = "+str(t1-t0)
- end sub
-
-