Sorting Function in LotusScript

Form SharePlace

Dim lstMyList List As String
Dim strTags As String

lstMyList ("B") = "List"
strTags = |"B"|
lstMyList ("A") = "Sorting"
strTags = StrTags & |:"A"|
lstMyList ("D") = "Simple"
strTags = StrTags & |:"D"|
lstMyList ("C") = "Is"
strTags = StrTags & |:"C"|


Then, use @Sort formula function to sort "lstMyList".
Dim varTagsArray As Variant
varTagsArray = Evaluate (|@sort (| & strTags & |)|)

Second choice: Bubble Sort Algorithm
Form: IBM

Sub bub_sort (in_array As Variant)
'returns a sorted array based on a complexity of O(n^2) using a bubble sort
If Not Isarray(in_array) Then
Print "bub_sort: not receiving array"
Exit Sub
End If

Dim top, bot, cur, cur2 As Integer
top=Ubound (in_array)
bot=Lbound (in_array)

If top=bot Then
Print "bub_sort: only one element"
Exit Sub
End If

Dim tmp_element As Variant

For cur=bot To top
cur2=cur
Do While cur2 > bot 'bubble up
If (in_array(cur2) > in_array(cur2-1)) Then
Exit Do
Else
'swap
tmp_element=in_array(cur2)
in_array(cur2)=in_array(cur2-1)
in_array(cur2-1)=tmp_element
End If
cur2=cur2-1
Loop
Next
End Sub

February 2012

Sun Mon Tue Wed Thu Fri Sat
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29      

Archives

Powered by Movable Type 4.34-en

About this Entry

This page contains a single entry by philipz published on December 20, 2007 5:58 PM.

如何恢復 Linux 上刪除的文件 was the previous entry in this blog.

函數編程(Functional Programming) is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.