打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
VBA中的数组排序
Function BubbleSort(TempArray As Variant)
    Dim Temp As Variant
    Dim i As Integer
    Dim NoExchanges As Integer
    ' Loop until no more 'exchanges' are made.
    Do
        NoExchanges = True
        ' Loop through each element in the array.
        For i = 1 To UBound(TempArray) - 1
            ' If the element is greater than the element
            ' following it, exchange the two elements.
            If TempArray(i) > TempArray(i + 1) Then
                NoExchanges = False
                Temp = TempArray(i)
                TempArray(i) = TempArray(i + 1)
                TempArray(i + 1) = Temp
            End If
        Next i
    Loop While Not (NoExchanges)
End Function
Sub BubbleSortMyArray()
    Dim TheArray As Variant
    ' Create the array.
    TheArray = Array(15, 8, 11, 7, 33, 4, 46, 19, 20, 27, 43, 25, 36)
    ' Sort the Array and display the values in order.
    BubbleSort TheArray
    For i = 1 To UBound(TheArray)
        MsgBox TheArray(i)
    Next i
End Sub
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Excel VBA 自定义MyXLOOKUP函数
公历农历转换VB类
C#不重复输出一个数组中所有元素的方法
VB中如何给一维字符串数组赋值
贪心算法在背包中的应用—编程爱好者网站 http://www.programfan.com
算法系列15天速成
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服