Domino Code Fragment

Code Name*
Sort - Bubble Sort Algorithm
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.18.226.251.68
Description*
Sorts an array of data using the Bubble Sort Algorithm
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
In a worst case scenario the bubble sort has to do elements 2 /2 compares and almost as many swaps. If file is in reverse order then the ith bubble sort pass requires N - i comparisons and exchanges. Keep variable temp as variant thus either a text or number array can be sorted.
Files/Graphics attachments (if applicable): Code:
The Bubble sort is the simplest possible sort available. Simply put, it runs up the list,
item by item, over and over again pushing small elements down a notch at a time, and
larger elements up a notch until they're in the right place. When the array is run through
completely and no swaps are made, the sort is assumed to be compleate.


PROS: Not many, but the bubble sort is the fastest sorting method on an already-sorted set
of data. Easy to remember and regurgitate on the fly.

CONS: Extremely compare and swap intensive. In a nutshell, keep away from this sort
unless you have a really good reason to use it.

Pass 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 names you provide.

Sub bubble (arrayelts As Variant)
Dim swapped As Integer
Dim loope As Integer
Dim temp As Variant
Dim listsize As Integer
listsize = Ubound(arrayelts)
Do
swapped = 0
'Assume array sorted
For loope = 0 To listsize - 1
'Run through all the elements in the array
If arrayelts(loope + 1) < arrayelts(loope) Then
'Check and see if we need to swap
temp = arrayelts(loope)
'Yes, swap the current and next elements
arrayelts(loope) = arrayelts(loope + 1)
arrayelts(loope + 1) = temp
swapped = 1
'Do another iteration, array not sorted
End If
Next loope
Loop Until swapped = 0
End Sub