Question: Java Create a program named MysterySort.java then copy the following implementation of this mystery sort to your program: M3BGA1.txt Your main method accepts a number
Java
- Create a program named MysterySort.java then copy the following implementation of this mystery sort to your program:
- M3BGA1.txt
- Your main method accepts a number N from the command argument list. Then use the number N to create N-element int array.
- Assign random numbers between [0, Integer.MAX_VALUE) to each of the N elements of the array.
- Call isSorted method to test if the array is sorted in ascending order. Print the array elements.
- Call mysterySort method to sort the array.
- Call isSorted method again to verify the array was sorted successfully. Print the array elements.
- Once completed, test your program with different numbers of N and screenshot your result .
- Please include the following in the Word document you created for the assignment for the final submission:
- Answer this question: What kind of sort is this mystery sort? What is the average Big O for this sort?
- Copy/paste your completed code in MysterySort.java
- Insert at least one screenshot of the running output in #7 above
Mystery Sort File
public static void mysterySort(int[] arr). {
for(int i=0; i for(int k=0; k if(arr[k]>arr[k+1]) { //swapint hold=arr[k+1]; arr[k+1]=arr[k]; arr[k]=hold; } } } } public static Boolean isSorted(int[] arr) { for(int i=1; i if(arr[i] < arr[i-1]) return false; } return true; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
