Question: I need help writing this code. I have been asked to fill in certain parts and have been giving the tester to make sure that
I need help writing this code. I have been asked to fill in certain parts and have been giving the tester to make sure that it works. You must write your own sorting algorithm. You may not use any built in algorithms such as Arrays.sort.
Here is the one that I need filled in:
/* Write the sort method for the sort class. It takes an array of Comparable and sorts it. Be sure and handle edge cases as pointed out by the Tester. No API calls to sort are allowed. */ public class Sort { public static void sort(Comparable [] array) { }//end sort }//end class Sort
Here is the tester:
/* Write the sort method for the Sort class in Sort.java. See the code below along with output.txt for how your sort should behave (fundamentally, it should sort the data passed in ascending order). DO NOT MODIFY THIS FILE. */ public class Tester { public static void main(String [] args) { String [] names4 = {"zippy", "bubba", "sparky", "arnold"}; String [] names3 = {"zippy", "bubba", "sparky"}; String [] names2 = {"zippy", "bubba"}; String [] names1 = {"bubba"}; String [] names0 = new String[0]; Integer [] numbers = {23, 0, 45, 0, 91, 99, 2}; //sort 4 names System.out.println("Before sorting 4 names:"); for (String name: names4) System.out.println(name); Sort.sort(names4); System.out.println(" After sorting 4 names:"); for (String name: names4) System.out.println(name); System.out.println(" Before sorting 3 names:"); for (String name: names3) System.out.println(name); Sort.sort(names3); System.out.println(" After sorting 3 names:"); for (String name: names3) System.out.println(name); System.out.println(" Before sorting 2 names:"); for (String name: names2) System.out.println(name); Sort.sort(names2); System.out.println(" After sorting 2 names:"); for (String name: names2) System.out.println(name); System.out.println(" Before sorting 1 name:"); for (String name: names1) System.out.println(name); Sort.sort(names1); System.out.println(" After sorting 1 name:"); for (String name: names1) System.out.println(name); System.out.println(" Before sorting 0 names:"); for (String name: names0) System.out.println(name); Sort.sort(names0); System.out.println(" After sorting 0 names:"); for (String name: names0) System.out.println(name); System.out.println(" Finally, let's sort something else - integers"); for (int num: numbers) System.out.println(num); Sort.sort(numbers); System.out.println(" After sorting the integers:"); for (int num: numbers) System.out.println(num); }//end main }//end class Tester
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
