I the SGrid 1.0 sort class to implement the QuickSort algorithm rather than Shell Sort. It seems to be quicker so here’s the code I used to implement it: Friend Sub QSortItems( _
ByRef vItems() As tGridCell, _
ByRef tRows() As tRowPosition)
quickSort vItems, tRows, 1, UBound(vItems, 2), UBound(vItems, 1)
End Sub
Private Sub quickSort( _
ByRef vItems() As tGridCell, _
ByRef tRows() As tRowPosition, _
l0 As Long, _
r0 As Long, _
NbColonnes As Long)
Dim l As Long
Dim r As Long
Dim vSortItems() As tGridCell
Dim iCol As Long
If r0 > l0 Then
l = l0
r = r0
ReDim vSortItems(1 To NbColonnes)
For iCol = 1 To NbColonnes
LSet vSortItems(iCol) = vItems(iCol, (l0 + r0) / 2)
Next iCol
While l <= r
While (l < r0) And pbGreater(vItems(), vSortItems(), l)
l = l + 1
Wend
While (r > l0) And Not pbGreater(vItems(), vSortItems(), r)
r = r - 1
Wend
If l <= r Then
If l <> r Then Echange vItems, tRows, l, r, NbColonnes
l = l + 1
r = r - 1
End If
Wend
If r > l0 Then quickSort vItems, tRows, l0, r, NbColonnes
If l < r0 Then quickSort vItems, tRows, l, r0, NbColonnes
End If
End Sub
|