Domino Code Fragment

Code Name*
Sort - QuickSort, IBMs
Date*
04/29/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.18.218.129.100
Description*
The following is an example of how to use LotusScript code within NotesViP
to sort an array.
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
This is also useful when trying to sort an unconnected data object. Before putting the data into the data object, create a TYPE with all the
column headings and store the information in an array. Then, sort the array
using the above script. Finally, add the data into the unconnected data
object from the array. Lotus FTP address: ftp://ftp.support.lotus.com/
Lotus Web address: http://www.lotus.com/ (c) 1996 Copyright Lotus Development, an IBM subsidiary
Files/Graphics attachments (if applicable): Code:

function dividearray(first as integer, last as integer)
'
' Splits the array based on first number in array passed to it
'

dim temp as integer
dim holder1, holder2 as integer
dim count1, count2 as integer


temp = numbers(first) 'Store starting point
count1 = first + 1
count2 = last 'Store starting and ending points


while count1 <> count2 'Do while array is not divided
while numbers(count1) < temp and count1 < last
count1 = count1 +1
wend
holder1 = numbers(count1) 'Holds position of first swap
value
while numbers(count2) > temp and count2 > first
count2 = count2 - 1
wend
holder2 = numbers(count2) 'Holds position of second swap
value
if holder2 < holder1 and count1 < count2 then 'Swap values
numbers(count1) = holder2
numbers(count2) = holder1
else
count1 = count2
end if
wend


if numbers(count1) < temp then 'Swap final mid point
numbers(first) = numbers(count1)
numbers(count1) = temp
end if


if first + 1 = last then '2 numbers left store dividearray
as first
dividearray = first
elseif count1 = last then
dividearray = last -1 'First value moves to last position
else
dividearray = count1 'All other instances
end if
count1 = first + 1 'Reset start and end points
count2 = last
end function


sub quicksort(first as integer, last as integer)
'
' Recursive sorting routine
'

dim middle as integer
dim temp as integer


if last = first then exit sub 'If at end of number exit sub
middle = dividearray(first,last) 'Get dividearray value
call quicksort(first, middle) 'Sort first half of array
call quicksort(middle + 1, last) 'Sort second half of array
end sub