- ·上一篇内容:程序员高薪背后的秘密:程序员的技能杀伤力
- ·下一篇内容:VBA中实现选择排序算法
使用VBA实现冒泡法排序
Public Sub BubbleSort(ByRef lngArray() As Long)
Dim iOuter As Long
Dim iInner As Long
Dim iLBound As Long
Dim iUBound As Long
Dim iTemp As Long
iLBound = LBound(lngArray)
iUBound = UBound(lngArray)
'冒泡排序
For iOuter = iLBound To iUBound - 1
For iInner = iLBound To iUBound - iOuter - 1
'比较相邻项
If lngArray(iInner) > lngArray(iInner + 1) Then
'交换值
iTemp = lngArray(iInner)
lngArray(iInner) = lngArray(iInner + 1)
lngArray(iInner + 1) = iTemp
End If
Next iInner
Next iOuter
End Sub
评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论