Two sorts and one method to reverse an array
Two sorts and one method to reverse an array
Rate Two sorts and one method to reverse an array
(2(2 Vote))
Public Sub bubbleSort(Arr(), Optional sortAscending As Boolean = True)
Dim x As Long, y As Long, vy, vx, temp
Dim lo As Long, up As Long, incr As Integer
If sortAscending Then
lo = LBound(Arr): up = UBound(Arr): incr = 1
Else
lo = UBound(Arr): up = LBound(Arr): incr = -1
End If
For y = lo To up Step incr
For x = y + incr To up Step incr
vx = Arr(x): vy = Arr(y)
If vx < vy Then
Arr(y) = vx
Arr(x) = vy
End If
Next x
Next y
End Sub
Public Sub bubbleSortText(Arr(), Optional sortAscending As Boolean = True)
Dim x As Long, y As Long, vy, vx, temp
Dim lo As Long, up As Long, incr As Integer
If sortAscending Then
lo = LBound(Arr): up = UBound(Arr): incr = 1
Else
lo = UBound(Arr): up = LBound(Arr): incr = -1
End If
For y = lo To up Step incr
For x = y + incr To up Step incr
vx = Arr(x): vy = Arr(y)
If StrComp(vx, vy, vbTextCompare) = -1 Then
Arr(y) = vx
Arr(x) = vy
End If
Next x
Next y
End Sub
Public Sub arrayReverse(Arr())
Dim tmp
Dim i As Long, j As Long, lower As Long, upper As Long, mx As Long
lower = LBound(Arr)
upper = UBound(Arr)
If (upper <> lower) Then
If (upper Mod 2 = 0) Then mx = upper / 2 - 1 Else mx = upper \ 2
For i = lower To mx
j = upper - i
tmp = Arr(j)
Arr(j) = Arr(i)
Arr(i) = tmp
Next
End If
End Sub
Two sorts and one method to reverse an array Comments
No comments yet — be the first to post one!
Post a Comment