<%
Dim Item
For Each Item In CombSort( Array( "jonny", "steve", "bill", "brian", "alfred" ) )
Response.Write Item & "<BR>"
Next
' returns:
' alfred
' bill
' brian
' jonny
' steve
Dim Item
For Each Item In CombSort( Array( 512, 10, 81, 6, 452 ) )
Response.Write Item & "<BR>"
Next
' returns:
' 6
' 10
' 81
' 452
' 512
%>
<%
Private Function CombSort(byVal UnsortedArray)
Dim I, J, Temp, Gap, Swapped
Dim ArrSize, Combcom, Combswap
Const Shrink = 1.3
ArrSize = UBOUND( UnsortedArray )
Gap = Arrsize - 1
Do
Gap = Int(Gap / Shrink)
Swapped = True
Combcom = Combcom + 1
For J = 0 To Arrsize - Gap
If UnsortedArray(J) > UnsortedArray(J + Gap) Then
Temp = UnsortedArray(J)
UnsortedArray(J) = UnsortedArray(J + Gap)
UnsortedArray(J + Gap) = Temp
Swapped = False
Combswap = Combswap + 1
End If
Next
Loop Until Not Swapped And Gap = 1
CombSort = UnsortedArray
End Function
%>