Private Sub Command1_Click()
Dim c(100000) As Long
Dim b() As Long
Dim i As Long
For i = 0 To UBound(c)
c(i) = Fix(Rnd * 100000)
Next
longSort c, b
For i = 0 To UBound(b)
Print b(i)
Next
End Sub
'==============================================
'正整数快速排序法.
'适合正整数,速度极快,数的范围越大,耗费的内存越多
'对相同的元素进行剔除!!
Sub longSort(Ay() As Long, AySort() As Long)
'Ay():排序前数组
'AySort:排序后的数组
'==============================================
Dim max As Long
Dim min As Long
Dim bY() As Boolean
Dim i As Long
Dim count As Long
max = Ay(0)
min = Ay(0)
'找出最大,最小值
For i = 0 To UBound(Ay)
If Ay(i) > max Then max = Ay(i)
If Ay(i) < min Then min = Ay(i)
Next
'把存在的数的布尔值设成真
ReDim bY(max - min)
For i = 0 To UBound(Ay)
bY(Ay(i) - min) = True
Next
'排序
For i = 0 To max - min
If bY(i) = True Then
ReDim Preserve AySort(count)
AySort(count) = i + min
count = count + 1
End If
Next
End Sub
本文介绍了一种适用于正整数的快速排序方法,并通过VB编程语言实现了该算法。此方法不仅速度快,而且能够有效剔除重复元素,特别适合处理大数据集。文章通过具体的示例代码展示了排序过程。

1万+

被折叠的 条评论
为什么被折叠?



