Ejemplo n.º 1
0
void heap<T, Compare>::heapifyDown( size_t currentIdx ) {
    /// @todo Implement the heapifyDown algorithm.
	 if(!hasAChild(currentIdx))
        return;
    size_t pirorChildIdx =maxPriorityChild(currentIdx );
    if( !higherPriority( _elems[ currentIdx ], _elems[ pirorChildIdx ] ) ) {
        std::swap( _elems[ currentIdx ], _elems[ pirorChildIdx ] );
        heapifyDown(pirorChildIdx);
    }
}
Ejemplo n.º 2
0
size_t heap<T, Compare>::maxPriorityChild( size_t currentIdx ) const {
    /// @todo Update to return the index of the child with highest priority
    ///   as defined by higherPriority()
	if(hasAChild(currentIdx))
	{
		if(higherPriority(_elems[leftChild(currentIdx)],_elems[rightChild(currentIdx)]))
			return leftChild(currentIdx);
		else
			return rightChild(currentIdx);
	}
    return 0;
}
Ejemplo n.º 3
0
void heap<T, Compare>::heapifyDown( size_t currentIdx ) {
    /// @todo Implement the heapifyDown algorithm.
	if(hasAChild(currentIdx))
	{
	size_t minChildIndex=maxPriorityChild(currentIdx);
		if(!higherPriority(_elems[currentIdx],_elems[minChildIndex]))
		{
			std::swap(_elems[currentIdx],_elems[minChildIndex]);
			heapifyDown(minChildIndex);
		}
	}
}