I'm working on an Assignment where we're to create our own Generic Linked List. The List takes a Comparator<T> in its constructor, and we are to use the compare method of that comparator in our sorting algorithm. I've got the List working and fully tested, but I'm having issues passing a comparator type.
Keeping in mind the comparator would be passed by an end-user, how would you define and pass a comparator?
The constructor looks like:
public SorterList(final Comparator<T> comparator) {}
Thanks for any ideas!
Edit: When trying this, I get an error when creating the new SorterList object: image.
public static void main(String[] args) {
Comparator<Integer> comparator = new Comparator<Integer>() {
public int compare(final Integer o1, final Integer o2) {
// Ignore the simplicity of the compare
if(o1 > o2)
return 0;
else
return 1;
}
};
SorterList<Integer> intList = new SorterList<Integer>(comparator);
}