' Visual Basic 2008 9.0 .NET Examples - Sorting Arrays - Arrays : Module InsertionSortExample Sub Main() Dim count As Integer = 5 Dim upperbound As Integer = count - 1 Dim numbers(upperbound) As Integer ' Dim index As Integer For index = 0 To upperbound numbers(index) = (count ^ index) * 93 Mod 97 - (count \ (index + 1)) Next ' Console.Write("unsorted array : ") For index = 0 To upperbound Console.Write(numbers(index) & " ") Next Console.WriteLine() ' Dim unsortedCount As Integer = count - 1 Do Until unsortedCount = 0 Dim startIndexUnsortedPart As Integer = count - unsortedCount ' Dim backup As Integer = numbers(startIndexUnsortedPart) ' index = startIndexUnsortedPart - 1 Do While index >= 0 AndAlso numbers(index) > backup numbers(index + 1) = numbers(index) index -= 1 Loop ' numbers(index + 1) = backup ' unsortedCount -= 1 ' Console.Write("temporary array : ") For index = 0 To upperbound Console.Write(numbers(index) & " ") Next Console.WriteLine() Loop ' Console.Write("sorted array : ") For index = 0 To upperbound Console.Write(numbers(index) & " ") Next ' Console.ReadLine() End Sub End Module ' Visit www.studyvb.com for more examples. Copyright 2003-2008 De Wolf.