0% found this document useful (0 votes)
38 views2 pages

Bubble Sort 2022

The document describes a Visual Basic program that performs a bubble sort on an integer array. It initializes an array with 7 integers, then uses a nested for loop to compare adjacent elements and swap them if out of order, repeatedly passing through the array until it is fully sorted. It outputs the sorted array to the console.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views2 pages

Bubble Sort 2022

The document describes a Visual Basic program that performs a bubble sort on an integer array. It initializes an array with 7 integers, then uses a nested for loop to compare adjacent elements and swap them if out of order, repeatedly passing through the array until it is fully sorted. It outputs the sorted array to the console.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Dim mylist() As Integer = {25, 34, 98, 7, 41, 19, 5}

Dim temp As Integer


'Dim maxindex As Integer = 6
'Dim nomoreswaps As Boolean
'' n = maxindex - 1
For x = 1 To 6
For j = 0 To 5
If mylist(j) > mylist(j + 1) Then
temp = mylist(j)
mylist(j) = mylist(j + 1)
mylist(j + 1) = temp

End If
Next j
Next x

For x = 0 To 6
Console.WriteLine(mylist(x))
Next
Console.ReadKey()

Sub Main()
Dim mylist() As Integer = {25, 34, 98, 7, 41, 19, 5}
Dim n, j, temp As Integer
Dim maxindex As Integer = 6
Dim nomoreswaps As Boolean
n = maxindex - 1
Do
nomoreswaps = True
For j = 0 To n
If mylist(j) > mylist(j + 1) Then
temp = mylist(j )
mylist(j) = mylist(j + 1)
mylist(j + 1) = temp
nomoreswaps = False

End If
Next j
n = n - 1
Loop Until nomoreswaps = True
For x = 0 To 6
Console.WriteLine(mylist(x))
Next
Console.ReadKey()
Read

Dim yamini As String


Dim age As New IO.StreamReader("c:\users\ratta\desktop\abc.txt")
yamini = age.ReadLine
'Do While Not yamini Is Nothing
Do While age.Peek <> -1
Console.WriteLine(yamini)
yamini = age.ReadLine
Loop
age.Close()
Console.ReadKey()

Write
Dim name, age, sect As String
Dim filehandle As New IO.StreamWriter("c:\users\ratta\desktop\abc.txt")
Console.WriteLine("ënter age")
age = Console.ReadLine
While age <> "-1"

Console.WriteLine("enter name")
name = Console.ReadLine
Console.WriteLine("enter sect")
sect = Console.ReadLine
filehandle.WriteLine(name & ":" & age & ":" & sect)
Console.WriteLine("enter age")
age = Console.ReadLine

End While
filehandle.Close()

You might also like