Domino Code Fragment

Code Name*
Quicksort one less recursive call
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.3.128.199.88
Description*
Does a quicksort on an array!
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
Sub quicksort (byval l As Integer, byval r As Integer, arrayelts() As Variant)
' Note that as we are modifying l and r, they are passed by value
Dim m As Variant
Dim i As Integer
Dim t As Variant
Dim j As Integer


'Loop until there's nothing to sort
while (r > l)


'Initialize boundaries, nominate a value to sort
m = arrayelts(l)
j = r
i = l
'Repeat until i and j "meet in the middle"
While (i < j)
'Push in the boundaries while data is sorted
While (arrayelts(i) <= m And i < r)
i = i + 1
Wend
While (arrayelts(j) > m)
j = j - 1
Wend
'If there is data between i and j something is out of order - swap it
If i < j Then
t = arrayelts(i)
arrayelts(i) = arrayelts(j)
arrayelts(j) = t
End If
Wend


'Swap the nominated and bottom values - why we came here
t = arrayelts(l)
arrayelts(l) = arrayelts(j)
arrayelts(j) = t



'sort data either side of upper bound
'Recurse to sort the smallest and oop to sort the larger side
if ( j - l < r - j ) then
Call quicksort (l, j - 1, arrayelts)
l = j + 1
else
Call quicksort ((j + 1), r, arrayelts)
r = l - 1
end if
End while


End Sub