程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> 關於.NET >> 冒泡排序,冒泡排序法

冒泡排序,冒泡排序法

編輯:關於.NET

冒泡排序,冒泡排序法


Imports System.Threading

Module Module1

    Sub Main()

        Dim int_array(9) As Integer
        Dim rnd As New Random

        '填充數組元素
        For i As Integer = 0 To int_array.Length - 1
            int_array(i) = rnd.Next(0, 100)
            Console.Write(int_array(i) & ", ")
            Thread.Sleep(150)
        Next

        Console.WriteLine(vbCrLf & "-------------------------------")

        Dim x As Integer
        x = 2
        Do
            For i As Integer = 0 To int_array.Length - x
                If (int_array(i) > int_array(i + 1)) Then
                    Exchange(int_array(i), int_array(i + 1))
                End If
            Next i

            x += 1

            '向控制台輸出結果
            For j As Integer = 0 To int_array.Length - 1
                Console.Write(int_array(j) & ", ")
            Next j
            Console.WriteLine()
        Loop While (x <= int_array.Length)

        Console.ReadKey()
    End Sub

    '交換值
    Public Sub Exchange(ByRef val1 As Integer, ByRef val2 As Integer)
        Dim temp As Integer
        temp = val1
        val1 = val2
        val2 = temp
    End Sub

End Module

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved