首页 > 开发 > 综合 > 正文

利用数组进行冒泡法排序举例

2024-07-21 02:25:45
字体:
来源:转载
供稿:网友

语法:vb .net
环境:.netframeword1.1

dim i, j, k as integer
        dim tmp as integer
        dim sr(20) as string
        dim rr(20) as string

        sr(1) = 2
        sr(2) = 11
        sr(3) = 1
        sr(4) = 4
        sr(5) = 3
        sr(6) = 12
        sr(7) = 5
        sr(8) = 13
        sr(9) = 7
        sr(10) = 14
        sr(11) = 6
        sr(12) = 18
        sr(13) = 8
        sr(14) = 17
        sr(15) = 9
        sr(16) = 10
        sr(17) = 15
        sr(18) = 19
        sr(19) = 16

        for i = 1 to 19
            for j = 1 to 20 - i
                if convert.toint16(sr(j)) < convert.toint16(sr(j + 1)) then
                    tmp = sr(j)
                    sr(j) = sr(j + 1)
                    sr(j + 1) = tmp
                end if
            next
        next


        for i = 1 to 19
            t1.text = t1.text + sr(i) + vbcrlf
        next 


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表