I read the API-interface the Java collection, part of the priority queue, which is implemented by Josh Bloch and Doug Lee, two works of the maestro.
Java PriorityQueue implemented with a heap array.
The following code fragments are shown from PriorityQueue.java , line 600:
private E removeAt(int i) { the list with one earlier than private E removeAt(int i) { element private E removeAt(int i) { to private E removeAt(int i) { last element private E removeAt(int i) { s]; private E removeAt(int i) { : private E removeAt(int i) { ) { private E removeAt(int i) {
I wonder what moved the element that used to be at the bottom of the heap should be large from the subtree of i . Method siftDown reasonable, after a siftDown smallest of subtrees will be raised to the position i .
The question is, if i is not changed, i.e., moved still exists after siftDown , it seems to me that the subtree has been created, it does not have to be siftUp again
Why Josh lifts them back to the top?
I hope that those who read the code can help!
source share