ReDim 擷取成一維陣列(起限 To 迄限) As Variant
ReDim 索引陣列(起限 To 迄限) As Long
If 排序維度 = 1 Then
For X = 起限 To 迄限
擷取成一維陣列(X) = 原始二維陣列(X, 排序鍵值)
索引陣列(X) = X
Next X
Else
For Y = 起限 To 迄限
擷取成一維陣列(Y) = 原始二維陣列(排序鍵值, Y)
索引陣列(Y) = Y
Next Y
End If
If 排序維度 = 1 Then
For X = 起限 To 迄限
For Y = LBound(原始二維陣列, 2) To UBound(原始二維陣列, 2)
原始二維陣列(X, Y) = 複製原始二維陣列(索引陣列(X), Y)
Next Y
Next X
Else
For Y = 起限 To 迄限
For X = LBound(原始二維陣列, 1) To UBound(原始二維陣列, 1)
原始二維陣列(X, Y) = 複製原始二維陣列(X, 索引陣列(Y))
Next X
Next Y
End If
End Sub
Public Sub 二維陣列快速插入穩定遞增排序(ByRef 原始一維陣列 As Variant, ByRef 索引陣列() As Long, ByVal 起限 As Long, ByVal 迄限 As Long)
Dim 起陣列 As Variant
Dim 基陣列 As Variant
Dim 迄陣列 As Variant
Dim 索引起陣列() As Long
Dim 索引基陣列() As Long
Dim 索引迄陣列() As Long
ReDim 起陣列(迄限 - 起限) As Variant
ReDim 基陣列(迄限 - 起限 + 1) As Variant
ReDim 迄陣列(迄限 - 起限) As Variant
ReDim 索引起陣列(迄限 - 起限) As Long
ReDim 索引基陣列(迄限 - 起限 + 1) As Long
ReDim 索引迄陣列(迄限 - 起限) As Long
S = 0
M = 0
E = 0
For X = 起限 To 迄限
暫存 = 原始一維陣列(X)
索引暫存 = 索引陣列(X)
If 暫存 < 基準 Then
S = S + 1
起陣列(S) = 暫存
索引起陣列(S) = 索引暫存
ElseIf 暫存 = 基準 Then
M = M + 1
基陣列(M) = 暫存
索引基陣列(M) = 索引暫存
Else
E = E + 1
迄陣列(E) = 暫存
索引迄陣列(E) = 索引暫存
End If
Next X