Java Reference
In-Depth Information
0
(1)operations on the head, with
0
(lo
gn
) for general insertion. Anything
that requires traversing, such as removing a specific element or search-
ing for one, would be
0
(
n
)
There are six constructors:
public
PriorityQueue(int initialCapacity)
Creates a new
PriorityQueue
that can store
initialCapacity
ele-
ments without resizing and that orders the elements accord-
ing to their natural order.
public
PriorityQueue()
Creates a new
PriorityQueue
with the default initial capacity,
and that orders the elements according to their natural order.
public
PriorityQueue(int initialCapacity, Comparator<? super E>
comp)
Creates a new
PriorityQueue
that can initially store
initialCa-
pacity
elements without resizing, and that orders the ele-
ments according to the supplied comparator.
public
PriorityQueue(Collection<? extends E> coll)
Creates a new
PriorityQueue
whose initial contents are the
contents of
coll
. The capacity of the queue is initially 110%
of the size of
coll
to allow for some growth without resizing.
If
coll
is a
SortedSet
or another
PriorityQueue
, then this queue
will be ordered the same way; otherwise, the elements will be
sorted according to their natural order. If any element in
coll
can't be compared, a
ClassCastException
is thrown.
public
PriorityQueue(SortedSet<? extends E> coll)