Bubble Sort in VB.NET Console

In this tutorial, i will teach you how to create a program for bubble sorting using vb.net console. We all know that bubble sort is a sorting algorithm that is repeatedly searching through lists that need to be sorted, comparing each pair of items and swapping them if they are in the wrong order. Now, let's start this tutorial! 1. Let's start with creating a Console Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Console Application. 2. Name your project as bubbleSort as your module. Note: This is a console application so we cannot have visual controls for this tutorial. 3. Add the following code in your module.
  1. Module bubbleSort
  2. Sub Main()
4. Make a function named sorting. This will automatically sort the inputted elements that we will create in Sub Main.
  1.     Sub sorting(ByVal x() As Integer, ByVal y As Integer)
  2.         Dim i, a, t As Integer
  3.         For i = 0 To y - 1
  4.             For a = i + 1 To y - 1
  5.                 If x(i) > x(a) Then
  6.                     t = x(i)
  7.                     x(i) = x(a)
  8.                     x(a) = t
  9.                 End If
  10.             Next
  11.         Next
  12.     End Sub
5. For entering number of elements, put this code below.
  1. Console.WriteLine("Bubble Sorting")
  2.         Console.WriteLine()
  3.         Dim num, i As Integer
  4.         Console.Write("Enter Number of Elements: ")
  5.         num = CInt(Console.ReadLine)
  6.         Dim arr(num) As Integer
  7.         Console.WriteLine()
  8.         For i = 0 To num - 1
  9.             Console.Write("Enter Element(" & (i + 1) & "): ")
  10.             arr(i) = CInt(Console.ReadLine)
  11.         Next
6. For printing the inputted elements above, put this code below.
  1. Console.WriteLine()
  2.         Console.WriteLine("Inputted Elements")
  3.         Console.WriteLine()
  4.         For i = 0 To num - 1
  5.             Console.WriteLine("Element in (" & i & "): " & arr(i))
  6.         Next
7. Lastly, we will code for the sorting of elements (bubble sort), put this code below.
  1.         Console.WriteLine()
  2.         sorting(arr, num)
  3.         Console.WriteLine("Sorted Elements")
  4.         Console.WriteLine()
  5.         For i = 0 To num - 1
  6.             Console.WriteLine("Element in (" & i & "): " & arr(i))
  7.         Next
  8.         Console.ReadLine()
Output: output Hope this program helps! :) Best Regards, Engr. Lyndon R. Bermoy IT Instructor/System Developer/Android Developer/Freelance Programmer If you have some queries, feel free to contact the number or e-mail below. Mobile: 09488225971 Landline: 826-9296 E-mail:[email protected] Add and Follow me on Facebook: https://www.facebook.com/donzzsky Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

Comments

WOW THIS CODE WAS AMAZING!!! I LOVED IT, HIT ME UP AND ILL GIVE YOU SOME OF MINE

Add new comment