Exemplo n.º 1
0
void priority_queue<Object,Container,Compare>::pop( )
{
    if( empty( ) )
        throw UnderflowException( "Cannot pop an empty priority queue" );

    int hole = 1;
    int child;
    Object tmp = theItems.back( );
    theItems.pop_back( );
    int theSize = size( );

    for( ; hole * 2 <= theSize; hole = child )
    {
        child = hole * 2;
        if( child != theSize &&
                lessThan( theItems[ child ], theItems[ child + 1 ] ) )
            child++;
        if( lessThan( tmp, theItems[ child ] ) )
            theItems[ hole ] = theItems[ child ];
        else
            break;
    }

    if( !empty( ) )
        theItems[ hole ] = tmp;
}
Exemplo n.º 2
0
void deleteMin(void)
{
	if(isEmpty())
		throw UnderflowException();
	array[i]=array[currentSize--];
	percolateDown(1);
}
Exemplo n.º 3
0
void deleteMin(Comparable& minItem)
{
	if(isEmpty())
		throw UnderflowException();
	minItem=array[1];
	array[1]=array[currentSize--];
	percolateDown(1);
}
Exemplo n.º 4
0
void Stack<Object>::pop( )
{
    if( isEmpty( ) )
        throw UnderflowException( );

    ListNode *oldTop = topOfStack;
    topOfStack = topOfStack->next;
    delete oldTop;
}
Exemplo n.º 5
0
  void heap::deleteMin(huffmanNode* minItem)
  {
    if(isEmpty())
      throw UnderflowException();

    minItem = array[1];
    array[1] = array[currentSize--];
    percolateDown(1);
  }
 /**
  * Remove the minimum item.
  * Throws UnderflowException if empty.
  */
 void deleteMin( )
 {
     if( isEmpty( ) )
         throw UnderflowException( );
 
     LeftistNode *oldRoot = root;
     root = merge( root->left, root->right );
     delete oldRoot;
 }
Exemplo n.º 7
0
		Object deleteMin()
		{
			if( isEmpty() )
				throw UnderflowException();

			PairNode * oldRoot = root;

			if(root->leftChild == NULL)
			{
				root = NULL;
			}
			else
			{
				root = combineSiblings(root->leftChild);
			}
			Object o = oldRoot->item;
			delete oldRoot;
			oldRoot = NULL;
			return o;
		}
Exemplo n.º 8
0
const Object & priority_queue<Object,Container,Compare>::top( ) const
{
    if( empty( ) )
        throw UnderflowException( "Cannot top an empty priority queue" );
    return theItems[ 1 ];
}
Exemplo n.º 9
0
const Object & Stack<Object>::top( ) const
{
    if( isEmpty( ) )
        throw UnderflowException( );
    return topOfStack->element;
}
Exemplo n.º 10
0
 huffmanNode* heap::findMin() const
 {
   if(isEmpty())
     throw UnderflowException();
   return array[1];
 }