VB.NET example-insertion sort algorithm

Insertion sort algorithm

This is the VB example code for the insertion sort.

Module Module1

    Sub Main()

        Dim arr() As Integer = New Integer() {100, 12, 320, 34, 45, 90}

        'sort the array using insertion sort

        insertionSort(arr, arr.Length)

        Dim i As Integer

        For i = 0 To arr.Length - 1




        Console.ReadLine() 'wait for keypress

    End Sub


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

        Dim i, j As Integer

        For i = 1 To n - 1 Step 1

            Dim pick_item As Integer = dataset(i)

            Dim inserted As Integer = 0

            j = i - 1

            While (j >= 0 And inserted <> 1)


                If (pick_item < dataset(j)) Then


                    dataset(j + 1) = dataset(j)

                    j -= 1

                    dataset(j + 1) = pick_item


                Else : inserted = 1

                End If


            End While



    End Sub


End Module


biggie comment


cheers, merry xmas

prince jimenez comment

 prince jimenez

Its really Helpfull :)


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.