The rubric says "In a new class, write a static insertion sort method that takes in an array of Comparable objects...In this new class, create a main that tests your code by making an array of TravelGuide objects and passing it into your insertion sort. Also test that your code works properly for an array of Strings as well."
This is what I have:
The compareTo method in TravelGuide :
//compares calling object location to parameter location
public int compareTo(Object other){
return (this.location.compareTo(((TravelGuide)other).location));
}
Insertion sort in other class:
//insertion sort
public static void insertionSort(Comparable[] array){
int i, j;
Comparable newValue;
for (i = 1; i < array.length; i++) {
newValue = array[i];
j = i;
while (j > 0 && (array[j - 1].compareTo(newValue)>0)) {
array[j] = array[j - 1];
j--;
}
array[j] = newValue;
}
}
I'm very confused...thanks guys.