|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
'------------------------
'插入排序的算法
'------------------------
Function InsertSort(ByRef n As Variant) As Boolean
Dim j As Integer
Dim p As Integer, temp%
For p = 0 To UBound(n)
temp = n(p)
j = p
Do While j > 0
If n(j - 1) > temp Then
n(j) = n(j - 1)
Else
Exit Do
End If
j = j - 1
Loop
n(j) = temp
Next
InsertSort = True
End Function
'冒泡排序
Public Function BobleSort(ByRef n As Variant) As Boolean
Dim i As Integer, j As Integer
Dim Swaped As Boolean
For i = 0 To UBound(n) - 1
For j = UBound(n) To i + 1 Step -1
If n(i) < n(j) Then
Swap n, j, i
End If
Next
Next
End Function
Public Function Swap(ByRef n As Variant, ByVal i As Integer, ByVal j As Integer)
Dim temp%
temp = n(i)
n(i) = n(j)
n(j) = temp
End Function
|
评分
-
1
查看全部评分
-
|