VB.NET example-bubble sort algorithm

Bubble sort algorithm



This is VB example code for the bubble sort.

Module Module1

    Sub Main()

        Dim arr() As Integer = New Integer() {30, 12, 32, 34, 45, 90}

        'sort the array using bubble sort

        bubbleSort(arr, arr.Length)

        'output the sorted array

        Dim i As Integer

        For i = 0 To arr.Length - 1

            Console.WriteLine(arr(i))

        Next

        Console.ReadLine() 'wait for keypress

    End Sub

 

    Sub bubbleSort(ByVal dataset() As Integer, ByVal n As Integer)

        Dim i, j As Integer

        For i = 0 To n Step 1

            For j = n - 1 To i + 1 Step -1

                If (dataset(j) < dataset(j - 1)) Then

 

                    Dim temp As Integer = dataset(j)

                    dataset(j) = dataset(j - 1)

                    dataset(j - 1) = temp

 

                End If

 

            Next

        Next

    End Sub

End Module





Comments

Name:
Comment:
Enter the text:
CAPTCHA image

....................................................................................................................Home | Forum | About | Contact
This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.
Copyright @ 2011-2013 worldbestlearningcenter. All Rights Reserved.
Home Programming Web DB & App Questions Exercises Tips Programs FAQs Download About
Computer-Wbest
Popular Pages
You might like