Gosub Setup
 
Print "Sort Process Started..."
T = Timer()
Rem ######################################################################################
Rem Place All Your Entry Code In This Section Between The #### Lines.  Make Sure That When
Rem Your Code Is Finished The 'Elapsed = Timer() - T' Line is executed.
 
 
quicksort(0,272)
 
 
Rem ######################################################################################
Elapsed = Timer() - T: Rem Calculate Time Elapsed During Sort
Print "Sort Process Completed..."
Gosub SaveSortedList: Rem Write Sorted Array To Text File
Print
Print "Sorted File Written To Text File 'Sorted.txt'.  Sort Time: ";Str$(Elapsed);" ms"
End: Rem Program End
 
Rem **************************************************************************************
Rem ***                                   Procedures                                   ***
Rem **************************************************************************************
Setup:
   Sync On: Sync Rate 0
   Dim NameList$(272)
   Open To Read 1,"c:\NameList.txt"
   For FileNum = 0 To 272
      Read String 1,NameList$(FileNum)
   Next FileNum
   Close File 1
   Center Text 320,150,"273 Names Read Into Array NameList(0 .. 272)"
   Center Text 320,200, "Press The Space Bar To Commence Sort..."
   Repeat : Sync : Until SpaceKey()=1
   CLS
Return
 
SaveSortedList:
   If File Exist("c:\Sorted.txt") Then Delete File "c:\Sorted.txt"
   Open To Write 1,"c:\Sorted.txt"
   For FileNum = 0 To 272
      Write String 1,NameList$(FileNum)
   Next FileNum
   Write String 1,"Time Taken: "+Str$(Elapsed)+" ms"
   Close File 1
Return
 
Rem Place Any Procedures Required By Your Program Here:
 
 
 
Rem **************************************************************************************
Rem ***                                   Functions                                    ***
Rem **************************************************************************************
 
Rem Place Any Functions Required By Your Program Here:
 
function quicksort(start, endd)
   i = start
   j = endd
 
   if (endd - start >= 1)
      k$ = NameList$(start)
      while (j > i)
         while ((NameList$(i) <= k$) and (i <= endd) and (j > i))
            inc i
         endwhile
         while ((NameList$(j) > k$) and (j >= start) and (j >= i))
            dec j
         endwhile
         if (j > i) then swap(i,j)
      endwhile
      swap(start, j)
      quicksort(start, j-1)
      quicksort(j+1, endd)
   else
      exitfunction
   endif
endfunction
 
 
function swap(a, b)
   t$ = NameList$(a)
   NameList$(a) = NameList$(b)
   NameList$(b) = t$
endfunction