|
对结果数组进行排序,附我整理的二维数组冒泡排序:
'冒泡排序:【二维数组】排序
'arrSort 要进行排序的二维数组
'sortCol 排序列
'sortMode 排序模式:"+" 升序,"-" 降序
Public Sub BubbleSort2(ByRef arrSort As Variant, ByVal sortCol As Integer, _
Optional ByVal sortMode As String = "+")
Dim i&, j&, t&, Sorted As Boolean, temp, LastIndex&, SortBorder&
ReDim temp(LBound(arrSort, 2) To UBound(arrSort, 2))
SortBorder = UBound(arrSort) - 1
If sortMode = "+" Then
For i = LBound(arrSort) To UBound(arrSort)
Sorted = True
For j = LBound(arrSort) To SortBorder
If arrSort(j, sortCol) > arrSort(j + 1, sortCol) Then
Sorted = False
For t = LBound(arrSort, 2) To UBound(arrSort, 2)
temp(t) = arrSort(j, t)
arrSort(j, t) = arrSort(j + 1, t)
arrSort(j + 1, t) = temp(t)
Next
LastIndex = j
End If
Next
SortBorder = LastIndex
If Sorted Then Exit For
Next
ElseIf sortMode = "-" Then
For i = LBound(arrSort) To UBound(arrSort)
Sorted = True
For j = LBound(arrSort) To SortBorder
If arrSort(j, sortCol) < arrSort(j + 1, sortCol) Then
Sorted = False
For t = LBound(arrSort, 2) To UBound(arrSort, 2)
temp(t) = arrSort(j, t)
arrSort(j, t) = arrSort(j + 1, t)
arrSort(j + 1, t) = temp(t)
Next
LastIndex = j
End If
Next
SortBorder = LastIndex
If Sorted Then Exit For
Next
End If
End Sub |
|