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

  1. Create a program named MysterySort.java then copy the following implementation of this mystery sort to your program:
    • M3BGA1.txt
  2. Your main method accepts a number N from the command argument list. Then use the number N to create N-element int array.
  3. Assign random numbers between [0, Integer.MAX_VALUE) to each of the N elements of the array.
  4. Call isSorted method to test if the array is sorted in ascending order. Print the array elements.
  5. Call mysterySort method to sort the array.
  6. Call isSorted method again to verify the array was sorted successfully. Print the array elements.
  7. Once completed, test your program with different numbers of N and screenshot your result .
  8. 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!