Answer to Question #267270 in Visual Basic for Nicole

Question #267270

Description: Write a sorting function, that takes in an array of numbers (size n) and outputs the array of numbers as a list, in sorted sequence (highest value to lowest value)


Notes:


• Use any development language you wish


• Do not use any language’s in-built sorting function (example Javascript array.sort). We’re asking you to write the full sorting algorhythm yourself


Example


• simpleSort({1,2,3,4})


Output:


• 4,3,2,1


Question 8b. Bonus: Name the sorting algorhythm



1
Expert's answer
2021-11-17T06:29:15-0500


Module Module1


    Sub sortArray(ByVal arr As Integer())
        Dim temp As Integer = 0
        'Sort array using bubble sort.
        For i As Integer = 0 To 4 Step 1
            For j As Integer = 4 To i + 1 Step -1
                If (arr(j) > arr(j - 1)) Then
                    temp = arr(j)
                    arr(j) = arr(j - 1)
                    arr(j - 1) = temp
                End If
            Next
        Next
    End Sub
    Sub Main()
        Dim arr As Integer() = New Integer(5) {}
        


        Console.WriteLine("Enter array elements: ")
        For i = 0 To 4 Step 1
            Console.Write("Element[{0}]: ", i)
            arr(i) = Integer.Parse(Console.ReadLine())
        Next


        sortArray(arr)


        Console.WriteLine("Array after sorting: ")
        For i = 0 To 4 Step 1
            Console.Write("{0} ", arr(i))
        Next
        Console.WriteLine()


        Console.ReadLine()
    End Sub
End Module

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS