如何使用新的比较器和NO指定的初始容量创建PriorityQueue?

Java中,我不知道如何用新的比较器创建一个新的PriorityQueue但没有给出队列长度?我该如何创建它?

我知道我可以写:

Queue<Node> theQueue = new PriorityQueue<Node>(15,new Comparator<Node>();

但我希望队列可以像LinkedList一样工作,我的意思是它的长度不固定,我怎么能声明呢?

解决方法

没有这样的构造函数.根据JavaDocs,the default capacity is 11,您可以指定与无参数PriorityQueue构造函数的类似行为:
Queue<Node> theQueue = new PriorityQueue<Node>(11,new Comparator<Node>());

是的,the queue will grow if it needs to.

A priority queue is unbounded,but has an internal capacity governing the size of an array used to store the elements on the queue. It is always at least as large as the queue size. As elements are added to a priority queue,its capacity grows automatically. The details of the growth policy are not specified.

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...