I am looking for suggestions on how to handle some possible elements implementing comparable and some not.
I am currently trying to do it like this
class BinaryTree<E> {
private Comparator<E> comparator;
public <T extends Comparable<E>>() BinaryTree() {
comparator = (T a, T b) -> a.compareTo(b)
}
public BinaryTree(Comparator<E> comparator) {
this.comparator = comparator
}
}
//rest of the class (add, remove etc)
And then the comparator variable is used. I cant get it to compile tho.