Pages

Search This Blog

Bubble Sorting Using Function


Module BSFun

    Sub Main()
        Console.WriteLine("Bubble Sorting using Function")
        Console.WriteLine()
        Dim n, i As Integer
        Console.Write("Enter Number of Elements: ")
        n = CInt(Console.ReadLine)
        Dim arr(n) As Integer
        Console.WriteLine()
        For i = 0 To n - 1
            Console.Write("Enter Element(" & (i + 1) & "): ")
            arr(i) = CInt(Console.ReadLine)
        Next
        Console.WriteLine()
        Console.WriteLine("Before Sorting")
        Console.WriteLine()
        For i = 0 To n - 1
            Console.WriteLine("Element in (" & i & "): " & arr(i))
        Next
        sort_array(arr, n)
        Console.WriteLine("Sorted Array")
        Console.WriteLine()
        For i = 0 To n - 1
            Console.WriteLine("Element in (" & i & "): " & arr(i))
        Next
        Console.ReadLine()
    End Sub
    Sub sort_array(ByVal x() As Integer, ByVal y As Integer)
        Dim i, j, t As Integer
        For i = 0 To y - 1
            For j = i + 1 To y - 1
                If x(i) > x(j) Then
                    t = x(i)
                    x(i) = x(j)
                    x(j) = t
                End If
            Next
        Next
    End Sub
End Module

1 comment:

  1. Thanks Alot!!

    These Codes helped me alot

    ReplyDelete