Did something just because I thought it looks cool. Not fast, but cool:
Code:
Public Function ShearSort1(ByRef pvarArray As Variant)
Dim Log As Long, Rows As Long, Cols As Long
Dim pow As Long, div As Long
Dim h() As Long
Dim i As Long, k As Long, j As Long
Dim lMax As Long, lMin As Long
lMax = UBound(pvarArray) + 1
lMin = LBound(pvarArray)
pow = 1
div = 1
Do While i * i <= lMax
If i > 0 Then
If lMax Mod i = 0 Then div = i
Else
div = i
End If
i = i + 1
Loop
Rows = div
Cols = lMax \ div
Do While pow <= Rows
pow = pow * 2
Log = Log + 1
Loop
ReDim h(Rows)
For i = 0 To Rows
h(i) = i * Cols
Next i
For k = 0 To Log - 1
For j = 0 To Cols \ 2 - 1
For i = 0 To Rows - 1
ShearPart1 pvarArray, h(i), h(i + 1), 1, i Mod 2 = 0
Next i
For i = 0 To Rows - 1
ShearPart2 pvarArray, h(i), h(i + 1), 1, i Mod 2 = 0
Next i
Next j
For j = 0 To Rows \ 2 - 1
For i = 0 To Cols - 1
ShearPart1 pvarArray, i, Rows * Cols + i, Cols, True
Next i
For i = 0 To Cols - 1
ShearPart2 pvarArray, i, Rows * Cols + i, Cols, True
Next i
Next j
Next k
For j = 0 To Cols \ 2 - 1
For i = 0 To Rows - 1
ShearPart1 pvarArray, h(i), h(i + 1), 1, True
Next i
For i = 0 To Rows - 1
ShearPart2 pvarArray, h(i), h(i + 1), 1, True
Next i
Next j
For i = 0 To Rows - 1
h(i) = -1
Next i
End Function
Private Sub ShearPart1(ByRef a As Variant, ByVal Lo As Long, ByVal Hi As Long, ByVal Nx As Long, ByVal Up As Boolean)
Dim t As Variant
Dim j As Long
j = Lo
If Up Then
Do While j + Nx < Hi
If a(j) > a(j + Nx) Then
t = a(j)
a(j) = a(j + Nx)
a(j + Nx) = t
End If
j = j + 2 * Nx
Loop
Else
Do While j + Nx < Hi
If a(j) < a(j + Nx) Then
t = a(j)
a(j) = a(j + Nx)
a(j + Nx) = t
End If
j = j + 2 * Nx
Loop
End If
End Sub
Private Sub ShearPart2(ByRef a As Variant, ByVal Lo As Long, ByVal Hi As Long, ByVal Nx As Long, ByVal Up As Boolean)
Dim t As Variant
Dim j As Long
j = Lo + Nx
If Up Then
Do While j + Nx < Hi
If a(j) > a(j + Nx) Then
t = a(j)
a(j) = a(j + Nx)
a(j + Nx) = t
End If
j = j + 2 * Nx
Loop
Else
Do While j + Nx < Hi
If a(j) < a(j + Nx) Then
t = a(j)
a(j) = a(j + Nx)
a(j + Nx) = t
End If
j = j + 2 * Nx
Loop
End If
End Sub
Code:
Public Function ShearSort(ByRef plngArray() As Long)
Dim Log As Long, Rows As Long, Cols As Long
Dim pow As Long, div As Long
Dim h() As Long
Dim i As Long, k As Long, j As Long
Dim lMax As Long, lMin As Long
lMax = UBound(plngArray) + 1
lMin = LBound(plngArray)
pow = 1
div = 1
Do While i * i <= lMax
If i > 0 Then
If lMax Mod i = 0 Then div = i
Else
div = i
End If
i = i + 1
Loop
Rows = div
Cols = lMax \ div
Do While pow <= Rows
pow = pow * 2
Log = Log + 1
Loop
ReDim h(Rows)
For i = 0 To Rows
h(i) = i * Cols
Next i
For k = 0 To Log - 1
For j = 0 To Cols \ 2 - 1
For i = 0 To Rows - 1
ShearPart1 plngArray, h(i), h(i + 1), 1, i Mod 2 = 0
Next i
For i = 0 To Rows - 1
ShearPart2 plngArray, h(i), h(i + 1), 1, i Mod 2 = 0
Next i
Next j
For j = 0 To Rows \ 2 - 1
For i = 0 To Cols - 1
ShearPart1 plngArray, i, Rows * Cols + i, Cols, True
Next i
For i = 0 To Cols - 1
ShearPart2 plngArray, i, Rows * Cols + i, Cols, True
Next i
Next j
Next k
For j = 0 To Cols \ 2 - 1
For i = 0 To Rows - 1
ShearPart1 plngArray, h(i), h(i + 1), 1, True
Next i
For i = 0 To Rows - 1
ShearPart2 plngArray, h(i), h(i + 1), 1, True
Next i
Next j
For i = 0 To Rows - 1
h(i) = -1
Next i
End Function
Private Sub ShearPart1(ByRef a() As Long, ByVal Lo As Long, ByVal Hi As Long, ByVal Nx As Long, ByVal Up As Boolean)
Dim t As Long
Dim j As Long
j = Lo
If Up Then
Do While j + Nx < Hi
Compare aeShakersort, j, j + Nx
If a(j) > a(j + Nx) Then
Exchange aeShakersort, j, j + Nx
End If
j = j + 2 * Nx
Loop
Else
Do While j + Nx < Hi
Compare aeShakersort, j, j + Nx
If a(j) < a(j + Nx) Then
Exchange aeShakersort, j, j + Nx
End If
j = j + 2 * Nx
Loop
End If
End Sub
Private Sub ShearPart2(ByRef a As Variant, ByVal Lo As Long, ByVal Hi As Long, ByVal Nx As Long, ByVal Up As Boolean)
Dim t As Variant
Dim j As Long
j = Lo + Nx
If Up Then
Do While j + Nx < Hi
Compare aeShakersort, j, j + Nx
If a(j) > a(j + Nx) Then
Exchange aeShakersort, j, j + Nx
End If
j = j + 2 * Nx
Loop
Else
Do While j + Nx < Hi
Compare aeShakersort, j, j + Nx
If a(j) < a(j + Nx) Then
Exchange aeShakersort, j, j + Nx
End If
j = j + 2 * Nx
Loop
End If
End Sub