| .BZU. | 15-12-2009 11:07 PM | Program for Sorting the elements of an Array (bubble Sort) VB Code (By Sheraz) Code:
Module Module1
Sub Main()
Dim ar As Integer()
Dim temp As Integer
Dim my_index As Integer
ar = New Integer() {15, 8, 1, 6, 34, 7, 5, 342, 4, 9}
my_index = ar.GetUpperBound(0)
For j = 0 To 8
For i = 0 To my_index - 1 ' 1 is subtrcted to avoid INDEX OUT OF RANGE
If ar(i) > ar(i + 1) Then
temp = ar(i)
ar(i) = ar(i + 1)
ar(i + 1) = temp
End If
Next
my_index = my_index - 1
Next
For k = 0 To ar.GetUpperBound(0)
Console.WriteLine(ar(k))
Next
Console.ReadLine()
End Sub
End Module
|