I am testing the different sort methods (Selection, bubble insertion) and I am trying to use Comparator at the same time.
So far I have two classes; Main and Selectionsort.
My main looks like this:
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
String[] anArray = {"Ludo", "matador", "ChessTitan", "Rottefælden"};
for (int i=0; i<anArray.length-1; i++) {
for (int j=i+1; j<anArray.length; j++) {
if (anArray[j].compareTo(anArray[i]) < 1) {
String temp = anArray[i];
anArray[i] = anArray[j];
anArray[j] = temp;
}
}
}
for (String string : anArray) {
System.out.println(string);
}
}
}
And my selectionSort looks like this:
public class SelectionSort implements Comparator<String> {
@Override
public int compare(String o1, String o2) {
return o1.compareTo(o2);
}
}
What I want to do is use my Comparator when I use selection sort.
How is this possible?