' Visual Basic 2008 9.0 .NET Examples - Sorting Arrays - Arrays : Module BubbleSortExample 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 Do While unsortedCount > 1 Dim endIndexUnsortedPart As Integer = unsortedCount - 2 ' For index = 0 To endIndexUnsortedPart If numbers(index) > numbers(index + 1) Then Dim backup As Integer = numbers(index) numbers(index) = numbers(index + 1) numbers(index + 1) = backup End If Next ' 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.