我正在尝试使用包含N行* 15列的2D数组按列排序。我看到了quicksort算法,但它仅适用于对行进行排序(垂直)。我需要的是按列排序。有人帮我得到吗?这是我的尝试
Public Arr As Variant
Public Sub QuickSortHorizontally()
Dim i As Integer, j As Integer, k As Integer
Dim LbdArr As Integer, UbdArr As Integer, Pvt As Integer
LbdArr = 1
UbdArr = 15
For i = LBound(Mtz, 1) To UBound(arr, 1)
For j = LBound(arr, 2) - 1 To UBound(arr, 2) - 1
For k = LBound(arr, 2) To UBound(arr, 2)
Pvt = arr(i, UBound(arr, 2))
If arr(i, k) <= Pvt Then
arr(i, k) = arr(k, i)
End If
Debug.Print arr(i, k) 'Just to see if it works
Next k
Next j
Next i
End Sub
Sub SortAllCols()
Dim ws As Worksheet
Dim cols, rows As Long
Set ws = ActiveSheet
cols = ws.UsedRange.Columns.Count
rows = ws.UsedRange.Rows.Count
For i = 1 To rows
ws.Range(Cells(i, 1), Cells(i, cols)).Select
ws.Sort.SortFields.Clear
ws.Sort.SortFields.Add Key:=Range(Cells(i, 1), Cells(i, cols)), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ws.Sort
.SetRange Range(Cells(i, 1), Cells(i, cols))
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With
Next i
End Sub