-
Notifications
You must be signed in to change notification settings - Fork 9
/
BubbleSort_Enhanced.vb
38 lines (32 loc) · 1001 Bytes
/
BubbleSort_Enhanced.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'Bubble Sort Visual Basic Code
Module Module1
Sub main()
Dim height(5) As Integer
Dim swapped As Boolean
Dim temp As Integer
Dim maxsize As Integer
maxsize = 5
For count = 1 To 5
Console.Write(" Enter Height of a student in cenitmeters : ")
height(count) = Console.ReadLine()
Next
'sort the elements
Do
swapped = False
For count = 1 To maxsize - 1
If height(count + 1) < height(count) Then
temp = height(count)
height(count) = height(count + 1)
height(count + 1) = temp
swapped = True
End If
Next
maxsize = maxsize - 1
Loop Until swapped = False
'Print out the elements
For count = 1 To 5
Console.WriteLine(count & ": " & height(count))
Next
Console.ReadKey()
End Sub
End Module