PriorityQueue称作优先队列,与普通队列先进先出不同,优先级队列中优先级最高的元素最先出列。
一、属性
//默认容量,初始化队列没有穿容量参数时使用
private static final int DEFAULT_INITIAL_CAPACITY = 11;
/**
* Priority queue represented as a balanced binary heap: the two
* children of queue[n] are queue[2*n+1] and queue[2*(n+1)]. The
* priority queue is ordered by comparator, or by the elements'
* natural ordering, if comparator is null: For each node n in the
* heap and each descendant d of n, n <= d. The element with the
* lowest value is in queue[0], assuming the queue is nonempty.
*/
//元素数组
transient Object[] queue; // non-private to simplify nested class access
/**
* The number of elements in the priority queue.
*/
//元素数量
private int size = 0;
/**
* The comparator, or null if priority queue uses elements'
* natural ordering.
*/
//优先级的比较器,仅当元素为Comparable时可以为null
private final Comparator<? super E> com