Here, we implement a few of our sorting algorithms.
Our goal is to test our sorting methods, ensuring that they sort correctly. Specifically, we want the program to perform the following steps:
In order to perform these tasks, you should write and use the methods described below. Remember that as you write new methods, you should compile and test them before trying to write the next method!
Use emacs to create a file called SortingTest.java, which should contain the program named SortingTest.
public static int[] createUnsortedArray (int length, int maxValue)
This method should create an array of length randomly chosen int values between 0 and maxValue, and return a pointer to that array.
public static void showArray (int[] array, int numberElements)
This method should print the first numberElements elements from array.
public static int[] copyArray (int[] original)
Create a duplicate of the array to which original points, and return a pointer to the duplicate.
public static boolean isSorted (int[] array)
Return whether the elements within array are in ascending order.
Any three of four of the following:
public static void bubbleSort (int[] array)
public static void selectionSort (int[] array)
public static void countingSort (int[] array)
public static void mergeSort (int[] array)
Sort the elements of array in ascending order.
Hint: Not only should you test your program with every new method you write, but you should also test your program first with simple cases, and then with more complex ones. That is, try creating and sorting arrays with only 1 element. After fixing any bugs that arise, try 2 elements, then 3. It is likely that you will find more than 90% of your bugs before trying sizes larger than 3.
Submit, as lab-6, your SortingTest.java file using the cs11-submit command.