Iterating through PriorityQueue doesn't yield ordered results

后端 未结 3 1076
伪装坚强ぢ
伪装坚强ぢ 2021-01-25 00:56
import java.util.*;
class Priority{  
public static void main(String args[]){  

PriorityQueue queue=new PriorityQueue();  
queue.add(\"Amit\         


        
3条回答
  •  有刺的猬
    2021-01-25 01:42

    This question is answered in the Javadoc:

    The Iterator provided in method iterator() is not guaranteed to traverse the elements of the priority queue in any particular order.

    To traverse the PQ in sorted order you have to use the remove() method.

提交回复
热议问题