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

Bubble Sort

This document contains a Visual Basic module that implements the Bubble Sort algorithm to sort an array of integers. It includes a 'Sort' subroutine that repeatedly compares and swaps adjacent elements until the array is sorted, and a 'PrintArray' subroutine to display the sorted array. The initial array is defined with ten integers, and the sorting process continues until no more swaps are needed.

Uploaded by

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

Bubble Sort

This document contains a Visual Basic module that implements the Bubble Sort algorithm to sort an array of integers. It includes a 'Sort' subroutine that repeatedly compares and swaps adjacent elements until the array is sorted, and a 'PrintArray' subroutine to display the sorted array. The initial array is defined with ten integers, and the sorting process continues until no more swaps are needed.

Uploaded by

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

Imports System.

Console

Module BubbleSort
Dim Array() As Integer = {10, 8, 5, 9, 3, 4, 1, 6, 7, 2}
Dim Sorted As Boolean = False
Dim Boundary As Integer = Array.Length - 2
Dim temp As Integer

Sub Sort()
While Sorted = False
Sorted = True
For i = 0 To Boundary
If Array(i) > Array(i + 1) Then
temp = Array(i)
Array(i) = Array(i + 1)
Array(i + 1) = temp
Sorted = False
End If
Next
Boundary = Boundary - 1
End While
WriteLine("Array has been sorted.")
End Sub

Sub PrintArray()
For j = 0 To Array.Length - 1
WriteLine(Array(j))
Next
End Sub
End Module

You might also like