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$(280)
  Open To Read 1,"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("Sorted.txt") Then Delete File "Sorted.txt"
  Open To Write 1,"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(L,R)
		CheckL = L
		CheckR = R
		Check$ = NameList$((L+R)/2)
		repeat
 
			while NameList$(CheckL) < Check$
				inc CheckL
			endwhile
 
			while Check$ < NameList$(CheckR)
				dec CheckR
			endwhile
 
			if CheckL <= CheckR
 
				Buffer$ = NameList$(CheckL)
				NameList$(CheckL) = NameList$(CheckR)
				NameList$(CheckR) = Buffer$
 
				inc CheckL
				dec CheckR
			endif
 
		until CheckL >= CheckR
 
		if L < CheckR then QuickSort(L,CheckR)
		if CheckL < R then QuickSort(CheckL,R)
 
EndFunction