H
H
hsadik2019-12-18 19:30:38
Java
hsadik, 2019-12-18 19:30:38

PriorityQueue implementation?

Do I understand correctly that Java uses a binary heap as a data structure in PriorityQueue, and specifically the implementation of max-heap?
Judging by the description of the siftUp method inside the class:
Inserts item x at position k, maintaining heap invariant by promoting x up the tree until it is greater than or equal to its parent, or is the root.
Those. ensures that the added element moves up the tree as long as it is greater than or equal to its parent, and if so, does it mean that the maximum element sits at the root?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2020-01-15
@Terran37

The head of the queue is the smallest element.
The elements are ordered and depending on the comparator, i.e., not only the standard order.
The implementation is based on #heap#, and the storage is actually an array.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question