If I want to create priority queue of nodes, and each node has only one field (i.e. int val
) do I have to write a comparator for the priority queue?
The elements of the priority queue are ordered according to their natural ordering, or by a Comparator . If you don't want to use Comparator then implement Comparable in your Node class.