I'm sure a quicksort implementation has been posted before, but this one could help illustrate how it works for the unfamiliar.
`%Project Title%
`%Source File Name%
`======================
global arrsize as integer
arrsize=10
dim arr(arrsize) as integer
for n=0 to arrsize
arr(n)=rnd(arrsize)
next n
printArr()
wait key
quicksort(0,arrsize)
printArr()
wait key
end
function printArr()
x=0
y=0
w=text width(str$(arrsize))
for n=0 to arrsize
center text x+w/2,y,str$(arr(n))
y=y+16
if y+16>screen height()
y=0
x=x+w
endif
next n
endfunction
function printArrHighlight(a as integer,color1 as dword, b as integer, color2 as dword, c as integer, color3 as dword)
x=0
y=0
w=text width(str$(arrsize))
for n=0 to arrsize
if n=a
ink color1,0
center text x+w/2,y,str$(arr(n))
ink rgb(255,255,255),0
else
if n=b
ink color2,0
center text x+w/2,y,str$(arr(n))
ink rgb(255,255,255),0
else
if n=c
ink color3,0
center text x+w/2,y,str$(arr(n))
ink rgb(255,255,255),0
else
center text x+w/2,y,str$(arr(n))
endif
endif
endif
y=y+16
if y+16>screen height()
y=0
x=x+w
endif
next n
endfunction
function quicksort(first, last)
if first>=last then exitfunction
element=(first+last)/2
elementval=arr(element)
//initialize the sorting range
leftct=first+1
rightct=last
cls
printarrhighlight(element,rgb(0,255,0),leftct,rgb(255,0,0),rightct,rgb(0,0,255))
wait key
//swap the current element and the first element, just to get the current element
//out of the way.
arr(element)=arr(first)
arr(first)=elementval
//We're going to take elements and swap them until all the elements on one side of
//the array are larger than all the elements on another side. Then, we're going to
//place "element" back between those two sides, and then call quicksort on the two
//sides.
while leftct<rightct
while arr(leftct)<=elementval and leftct<rightct
inc leftct
cls
printarrhighlight(first,rgb(0,255,0),leftct,rgb(255,0,0),rightct,rgb(0,0,255))
wait key
endwhile
while arr(rightct)>elementval and leftct<rightct
dec rightct
cls
printarrhighlight(first,rgb(0,255,0),leftct,rgb(255,0,0),rightct,rgb(0,0,255))
wait key
endwhile
//Swap the two elements.
//We may have leftct=rightct, but since nothing happens if we swap the element with itself, we
//don't need to check for it.
tmp=arr(leftct)
arr(leftct)=arr(rightct)
arr(rightct)=tmp
cls
printarrhighlight(first,rgb(0,255,0),leftct,rgb(255,0,0),rightct,rgb(0,0,255))
wait key
endwhile
//now we definitely have leftct=rightct. If the value at this index is greater than
//elementval, we want to put the element back at leftct-1. Otherwise, we'll put it
//back at leftct.
if arr(leftct)>elementval
arr(first)=arr(leftct-1)
arr(leftct-1)=elementval
//if element is at leftct-1, we'll sort from first to leftct-2 and from leftct to last.
quicksort(first,leftct-2)
quicksort(leftct,last)
else
arr(first)=arr(leftct)
arr(leftct)=elementval
quicksort(first,leftct-1)
quicksort(leftct+1,last)
endif
endfunction
It colors the important elements so you can see how the algorithm runs.