类PriorityQueue<E>
来源:互联网 发布:c 与java socket 编辑:程序博客网 时间:2024/06/06 00:11
1、继承关系
- java.lang.Object
- java.util.AbstractCollection<E>
- java.util.AbstractQueue<E>
- java.util.PriorityQueue<E>
2、没有任何优先权的队列是基于头优先的,优先权队列中的元素排列顺序为自然顺序,或者根据队列创建时提供的比较器而定顺序,这都取决于队列在创建时使用的是哪个构造器。优先权队列不允许null元素。依赖于自然排序的优先权队列也不允许非可比元素的插入(这样做可能会导致ClassCastException)。
3、对头和队列中指定排序关系不大,如果多个元素都绑定了最小值,且对头为其中之一--那么这绑定会随之瓦解。队列检索了操作:poll,remove,peek,element,获取的都是对头元素。
4、优先级队列是不受限制的,但它本身有一个数组大小的容量来存储数据。它的大小通常最小为队列大小。当有元素添加到队列中时,它的容量会自动增长,增长策略细节没有指定。
5、该类实现了所有的集合和迭代的方法。迭代器提供的方法 iterator()
并未指定按照某一特定顺序来遍历元素,如果你需要按序遍历,考虑使用Arrays.sort(pq.toArray())。
6、注意该实现是非同步的。如果有线程修改队列,多个线程是无法使用队列中的元素的。取而代之,使用线程安全类PriorityBlockingQueue
。
7、实现注意:入队出队方法(offer,poll,remove,add)的时间复杂度为:O(log(n)) ;remove和contains方法为线性时间;遍历方法为常量时间,peek,element,size。
8、方法概况:
boolean
add(E e)
Inserts the specified element into this priority queue.
void
clear()
Removes all of the elements from this priority queue.
Comparator<? super E>
comparator()
Returns the comparator used to order the elements in this queue, or
null
if this queue is sorted according to the natural ordering of its elements.boolean
contains(Object o)
Returns
true
if this queue contains the specified element.Iterator<E>
iterator()
Returns an iterator over the elements in this queue.
boolean
offer(E e)
Inserts the specified element into this priority queue.
E
peek()
Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.
E
poll()
Retrieves and removes the head of this queue, or returns null if this queue is empty.
boolean
remove(Object o)
Removes a single instance of the specified element from this queue, if it is present.
int
size()
Returns the number of elements in this collection.
Object[]
toArray()
Returns an array containing all of the elements in this queue.
<T> T[]
toArray(T[] a)
Returns an array containing all of the elements in this queue; the runtime type of the returned array is that of the specified array.
Methods inherited from class java.util.AbstractQueue
addAll, element, remove
Methods inherited from class java.util.AbstractCollection
containsAll, isEmpty, removeAll, retainAll, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
containsAll, equals, hashCode, isEmpty, removeAll, retainAll
0 0
- 类PriorityQueue<E>
- java 优先队列 PriorityQueue<E>
- 优先级队列(java.util.PriorityQueue<E>)
- PriorityQueue类源码解析
- PriorityQueue
- PriorityQueue
- priorityqueue
- PriorityQueue
- PriorityQueue
- PriorityQueue
- PriorityQueue
- PriorityQueue
- PriorityQueue
- PriorityQueue
- PriorityQueue
- priorityQueue
- PriorityQueue
- PriorityQueue
- 利用Zipkin对Spring Cloud应用进行服务追踪分析
- IOS缓存管理之PINCache使用
- windows环境下用c++实现socket编程
- c#抽象类和方法注意事项
- springboot读取resource下的文本文件
- 类PriorityQueue<E>
- Comparing and Assessing Cloud Database Management Systems
- 使用AJax和JavaScript实现省市区三级联动
- Selenium Webdriver 的使用java执行js代码 解决 ScriptEngine不支持浏览器内置对象window,document的问题
- leaf and spine switches
- caffe学习笔记(八)caffe+MATLAB2016接口安装
- Leetcode #344 Reverse String
- 前端工程师需要明白的「像素」
- 一位资深程序员大牛给予Java初学者的学习路线建议