Domino Code Fragment

Code Name*
Sort - Quicksort Algorithm recursive
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.18.117.153.38
Description*
Sorts an array of data using the recursive Quicksort Algorithm
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
The worst case scenario is when the pivot is the largest (or smallest) element. In this case the running time is It has been shown that the average running time of quicksort is Keep variable m and t as variant. Thus either a text or integer array can be sorted.
Files/Graphics attachments (if applicable): Code:
Employs a "divide-and-conquer" approach to get the data sorted. Works on subsets of data to sort, for each subset two pointers, i and j,
are kept. In addition to this a sort-key is nominated (here, its the value at the left of the sublist being sorted). i and j are brought together
(i.e., i increases, j decreases) swapping items into order as they approach. When i and j sense that the nominated value belongs where
they're sitting they move it there and then sort the data either side of the nominated value's new point.

PROS: Lightning quick, the Quicksort algorithm attempts to only compare and swap each element with another once.

CONS: Although not very complicated, some structures are very difficult to code into a quicksort.

' Pass the lower bound of the array to l, the upper bound of the array to r and the array to arrayelts.
This is working on pass by reference once returned to the main program the array passed will be sorted. At that point you can save
it to a document field.

Example using input of names you provide.

Sub quicksort (l As Integer,r As Integer, arrayelts As Variant)
Dim m As Variant
Dim i As Integer
Dim t As Variant
Dim j As Integer

If r > l Then 'If there's nothing to sort, jump out
m = arrayelts(l)
'Initialize boundaries, nominate a value to sort
j = r
i = l

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

t = arrayelts(l)
'Swap the nominated and bottom values - why we came here
arrayelts(l) = arrayelts(j)
arrayelts(j) = t
Call quicksort (l, j - 1, arrayelts)
'Recurse and sort data either side of upper bound
Call quicksort ((j + 1), r, arrayelts)
End If
End Sub