0% found this document useful (0 votes)
6 views1 page

Insertion Sort

Uploaded by

msufwans
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Insertion Sort

Uploaded by

msufwans
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Module Module1

Sub Main()
Dim array(10) As Integer
Console.WriteLine("Enter 10 numbers to be sorted ")
For index = 1 To 10
Try
array(index) = Console.ReadLine()
Catch ex As Exception
Console.WriteLine(ex.Message)
index = index - 1
End Try
Next

' Insertion Sort method

Dim ItemToBeInserted, CurrentItem As Integer

For pointer = 2 To 10
ItemToBeInserted = array(pointer)
CurrentItem = pointer - 1
While (ItemToBeInserted < array(CurrentItem) And CurrentItem >= 1)
array(CurrentItem + 1) = array(CurrentItem)
CurrentItem = CurrentItem - 1
End While

array(CurrentItem + 1) = ItemToBeInserted
Next

For i = 1 To 10
Console.WriteLine("{0} element is {1}", i, array(i))
Next

Console.ReadKey()
End Sub

End Module

You might also like