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

Bubble Sort VB

Uploaded by

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

Bubble Sort VB

Uploaded by

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

' Written by Craig'n'Dave

Module Module1
' Bubble sort
Function bubble_sort(items() As String)
Dim n As Integer = items.Count
Dim index As Integer
Dim swapped As Boolean = True
Dim temp As String
' Start a new pass until no swap is made
While n > 0 And swapped = True
swapped = False
' Last item has bubbled to the top and no longer needs to be checked
n = n - 1
' Compare all items except those already sorted
For index = 0 To n - 1
If items(index) > items(index + 1) Then
temp = items(index)
items(index) = items(index + 1)
items(index + 1) = temp
swapped = True
End If
Next
End While
Return items
End Function

Sub Main()
' Main porogram starts here
Dim items() As String = {"Florida", "Georgia", "Delaware", "Alabama",
"California"}
items = bubble_sort(items)
Console.WriteLine(String.Join(", ", items))
End Sub
End Module

You might also like