在这里看看:
编辑: 引用的源(allexperts.com)此后已经关闭,但是这里是相关的作者评论:
网上有很多算法可用于排序。功能最广泛且通常最快的是Quicksort算法。下面是它的功能。
只需通过下数组边界(通常是
0
)和上数组边界(即UBound(myArray)
)传递值(字符串或数字;没关系)的数组来调用它。范例:
Call QuickSort(myArray, 0, UBound(myArray))
完成后,
myArray
将进行排序,您可以使用它来做自己想做的事情。
(来源:archive.org)
Public Sub QuickSort(vArray As Variant, inLow As Long, inHi As Long)
Dim pivot As Variant
Dim tmpSwap As Variant
Dim tmpLow As Long
Dim tmpHi As Long
tmpLow = inLow
tmpHi = inHi
pivot = vArray((inLow + inHi) \ 2)
While (tmpLow <= tmpHi)
While (vArray(tmpLow) < pivot And tmpLow < inHi)
tmpLow = tmpLow + 1
Wend
While (pivot < vArray(tmpHi) And tmpHi > inLow)
tmpHi = tmpHi - 1
Wend
If (tmpLow <= tmpHi) Then
tmpSwap = vArray(tmpLow)
vArray(tmpLow) = vArray(tmpHi)
vArray(tmpHi) = tmpSwap
tmpLow = tmpLow + 1
tmpHi = tmpHi - 1
End If
Wend
If (inLow < tmpHi) Then QuickSort vArray, inLow, tmpHi
If (tmpLow < inHi) Then QuickSort vArray, tmpLow, inHi
End Sub
请注意,这仅适用于一维(也称为“正常”?)阵列。(有一个工作的多维数组快速排序在这里。)
处理重复项时,这是稍微快一点的实现。可能是由于\ 2.好答案:)
为此非常感谢!我在2500个条目数据集上使用了插入排序,大约需要22秒才能正确排序。现在它在一秒钟内完成,这是一个奇迹!;)
此功能的作用似乎总是将源中的第一项移动到目标中的最后位置,并对数组的其余部分进行排序。
Still a nice solution 9+ years later. But unfortunately the referenced page allexperts.com no longer exists...
@Egalth - I've updated the question with the information that was on the original source