popovIliya

Buble Sort

Feb 18th, 2021
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Strict On
  2. Option Explicit On
  3.  
  4. Module BubleSort
  5.  
  6.     Sub Main()
  7.         Dim txt As String
  8.         Dim n As Integer
  9.         Dim x As Integer
  10.         Console.Write("Enter the number of elements in the array n= ")
  11.         txt = Console.ReadLine()
  12.         If (Integer.TryParse(txt, n)) Then
  13.             Dim a(n - 1) As Integer
  14.             For index = 0 To a.GetUpperBound(0)
  15.                 Console.Write("a({0})=", index)
  16.                 a(index) = CInt(Console.ReadLine())
  17.             Next
  18.             'sortirane
  19.            For row = 1 To a.Length - 1
  20.                 For i = 0 To a.Length - 2
  21.                     If a(i) > a(i + 1) Then
  22.                         x = a(i)
  23.                         a(i) = a(i + 1)
  24.                         a(i + 1) = x
  25.                     End If
  26.                 Next i
  27.             Next row
  28.             txt = ""
  29.             For index = 0 To a.Length - 1
  30.                 txt = txt & a(index) & vbNewLine
  31.             Next
  32.             Console.WriteLine(txt)
  33.         End If
  34.         Console.ReadKey()
  35.     End Sub
  36.  
  37. End Module
  38.  
Advertisement
Add Comment
Please, Sign In to add comment