Bubble sorting and Bubble Sorting

Source: Internet
Author: User

Bubble sorting and Bubble Sorting

Imports System. Threading

Module Module1

Sub Main ()

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

'Fill in the array element
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

'Output the result to the console
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

'SWAp Value
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.