home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / devtools / sbl / sbleval / quick.sbl < prev    next >
Encoding:
Text File  |  1993-04-08  |  1.5 KB  |  58 lines

  1. REM    **********************************************************************
  2. REM    ******************  Copyright Softbridge, Inc. ***********************
  3. REM    **********************************************************************
  4.  
  5. '---------------------------------------------------------------------------
  6. '-----------------------------Program Notes---------------------------------
  7. '   This program is an implementation of a recursive quicksort.  It is a
  8. '   good program to run in debug mode.  I usually open the 'calls' window
  9. '   in the debugger and then hit 'animate'.
  10. '---------------------------------------------------------------------------
  11.  
  12.  
  13. const max%=1000
  14.  
  15. dim a(MAX) as double
  16. dim count as integer
  17.  
  18.  
  19. sub quicksort(l as integer, r as integer)
  20.   dim v as double, t as double
  21.   dim i as integer, j%
  22.   if (r>l) then
  23.     v=a(r) : i=l-1 : j=r : a(0) = v
  24.     do
  25.       do : i=i+1 :   loop until a(i)>=v
  26.       do : j=j-1 :   loop until a(j)<=v
  27.       t=a(i) : a(i)=a(j) : a(j)=t
  28.     loop until (j<=i)
  29.     a(j)=a(i) : a(i)= a(r) : a(r)=t
  30.     call quicksort(l,i-1)
  31.     call quicksort(i+1,r)
  32.  end if
  33. end sub
  34.     
  35. sub display 
  36.  for i%=1 to count
  37.     print "i=", i, "a(i)=", a(i)
  38.  
  39.  next i
  40. end sub
  41.  
  42. sub main
  43.  
  44.  
  45.   count = val(command$)
  46.   while (count = 0)
  47.     count = val(inputbox("enter size of list"))
  48.   wend
  49.   t0    = timer
  50.   for i=1 to count
  51.     a(i) = rnd(0.5)
  52.   next i
  53.   call quicksort(1,count)
  54.   t1 = timer 
  55.   msgbox "elapsed time = "+str(t1-t0)
  56. end sub
  57.     
  58.