交換一個整數數組的價值和指數如何交換一個整數數組的價值和指數VB宏如何在VB宏
i(0 to 5) = {3,4,1,5,0,2}
To
i(0 to 5) = {4,2,5,0,1,3}
編輯...
三江源@Tim和@Cody
下面的函數是什麼我有,但尋找更好的和比較有效的方式做到這一點的/無陣列l_aiOldIndexSwap
Public Function SortValuePairs(ByRef l_aiValues() As Integer) As Integer()
Dim l_aiOldIndexSwap() As Integer
ReDim l_aiOldIndexSwap(LBound(l_aiValues) To UBound(l_aiValues))
For i = LBound(l_aiValues) To UBound(l_aiValues)
l_aiOldIndexSwap(l_aiValues(i)) = i
Next
SortValuePairs = l_aiOldIndexSwap
End Function
您使用什麼算法來執行示例中描述的交換? – 2011-12-19 09:44:30
我沒有爲此使用任何算法,但如果您可以指導我使用任何此類算法,那將會很好:) – Jose 2011-12-19 10:26:11
糟糕,我可能會誤導您使用「swap」關鍵字。對不起,我不確定使用哪些關鍵字。 – Jose 2011-12-19 10:44:20