Hi Sun,
For your first doubt
A PriorityQueue's elements are ordered either by natural ordering (in which case the elements that are sorted first will be accessed first) or according to a Comparator
Priority queue stores elements in a sorted order. This ordering could be in one of the two forms:-
1.Natural ordering
2.Using Comparator(ie Implementing the comparator interface and having our own custom sort.)
For your second doubt on how the code compiles:-
For priorityQueues we use the following three methods:-
1.offer()-To add elements to the queue
2.peek()-To get the highest priority element
3.poll()-To get the highest priority element and remove it from the queue.
A modified version of your code is given below:-
Hope this helps