void p_queue::pop() { assert(size() > 0); if(size() == 1) { --used; return; } heap[0] = heap[used - 1]; used --; size_type childIndex = 0; size_type childPriority = 0; size_type currentPriority = heap[0].priority; while(is_leaf(childIndex) == false) { childPriority = big_child_priority(childIndex); if(childPriority >= currentPriority) { childIndex = big_child_index(childIndex); swap_with_parent(childIndex); } else { break; } } }
p_queue::size_type p_queue::big_child_priority(size_type i) const // Pre: is_leaf(i) returns false // Post: The priority of "the bigger child of the item at heap[i]" // has been returned. // (The bigger child is the one whose priority is no smaller // than that of the other child, if there is one.) { assert( !is_leaf(i) ); size_type index = big_child_index(i); return heap[index].priority; }
void p_queue::pop() { assert(used > 0); heap[0].data = heap[used - 1].data; heap[0].priority = heap[used - 1].priority; used--; size_type i = 0; while( !is_leaf(i) ) { size_type index = big_child_index(i); swap_with_parent(index); i = index; } }