interface Queue<E>
Constructor
Queue<Integer> q = new LinkedList<Integer>();
0:0 | Throws exception | Returns special value |
---|---|---|
Insert | add(e) | offer(e) |
Remove | remove() | poll() |
Examine | element() | peek() |
Priority Queue
Based on priority heap. Order by natural ordering or user-defined comparator at the construction time.
Not synchronized. Thread safe PriorityBlockingQueue class.
O(log(n)) time for the enqueing and dequeing methods(offer
,poll
,remove()
andadd
); linear time for theremove(Object)
andcontains(Object)
methods; and constant time for the retrieval methods (peek
,element
, andsize
).
constructor
PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
frequently used methods
boolean - pq.add(e);
boolean - pq.offer(e);
boolean - pq.remove(object);
E - pq.poll();
E - pq.peek();
boolean - pq.contains(object);
int - pq.size();
object[] - pq.toArray();
Iterator<E> - pq.iterator();
interface Deque
双端队列(deque,全名double-ended queue)可以让你在任何一端添加或者移除元素,因此它是一种具有队列和栈性质的数据结构。
Deque<Integer> deque = new ArrayDeque<Integer>();
reference: https://www.kancloud.cn/kancloud/data-structure-and-algorithm-notes/72904