[Solved] Having trouble implementing a nested class comparator

You should provide inner class instance into Arrays.sort to compare points from view of parent class instance. To do it you should not create new instance in main() function, but get it from Point instance. So, in main function you should use something like this: Point pivot; … // set up pivot point here Arrays.sort(myPoints, … Read more

[Solved] TreeNode cannot be cast to java.lang.Comparable?

Your problem is that while the generic parameter of TreeNode is Comparable, the class itself is not. Change this: public static class TreeNode<E extends Comparable<E>> { To this: public static class TreeNode<E extends Comparable<E>> implements Comparable<TreeNode<E>> { Or if you don’t require the generic type to also be Comparable: public static class TreeNode<E> implements Comparable<TreeNode<E>> … Read more

[Solved] Implement a CompareTo in Java [closed]

To use java.util.PriorityQueue, your class need to implement Comparable or specify Comparator when create an instance of PriorityQueue. The elements in queue will be sorted from low value to high value, the element will be evaluated by Comparator.compare or Comparable.compareTo method. In your case, your class Person implements Comparable<Person>, you have to determine the order … Read more