Exemple #1
0
        void BinaryHeap<Comparable>::deleteMin( )
        {
            if( isEmpty( ) )
                throw Underflow( );

            array[ 1 ] = array[ currentSize-- ];
            percolateDown( 1 );
        }
        void Stack<Object>::pop( )
        {
            if( isEmpty( ) )
                throw Underflow( );

            ListNode *oldTop = topOfStack;
            topOfStack = topOfStack->next;
            delete oldTop;
        }
Exemple #3
0
        void BinaryHeap<Comparable>::deleteMax( Comparable & maxItem )
        {
            if( isEmpty( ) )
                throw Underflow( );

            maxItem = array[ 1 ];
            array[ 1 ] = array[ currentSize-- ];
            percolateDown( 1 );
        }
Exemple #4
0
T 
STLQueue_Adapter<T, QUEUE>::front (void) const
{
  // You fill in here.
  if(!is_empty())
    return queue_.front();
  else
    throw Underflow();
}
Exemple #5
0
        void BinaryHeap<Comparable>::deleteMin( int & minItem )
        {
            if( isEmpty( ) )
                throw Underflow( );

            minItem = cities[ 1 ]->current;
            array[ 1 ] = array[ currentSize-- ];
            percolateDown( 1 );
        }
Exemple #6
0
void 
STLQueue_Adapter<T, QUEUE>::dequeue (void)
{
  // You fill in here.
  if(!is_empty())
    queue_.pop();
  else
    throw Underflow();
}  
Exemple #7
0
Object Queue<Object>::dequeue( )
{
    if( isEmpty( ) )
        throw Underflow( );

    currentSize--;
    Object frontItem = theArray[ front ];
    increment( front );
    return frontItem;
}
Exemple #8
0
template <class T> T 
AQueue<T>::front (void) const
{

  if (!is_empty())
    return queue_[head_];
  else
    throw Underflow();

}
Exemple #9
0
        Comparable BinaryHeap<Comparable>::deleteMax( )
        {
            if( isEmpty( ) )
                throw Underflow( );

            Comparable temp = array[1];
            array[ 1 ] = array[ currentSize-- ];
            percolateDown( 1 );

            return temp;
        }
Exemple #10
0
        Object QueueLL<Object>::dequeue( )
        {
          if( isEmpty( ) )
                throw Underflow( );

          Object frontItem = head->element;
          ListNode<Object> *temp = head->next;
          delete head;
          head = temp;

          return frontItem;
        }
Exemple #11
0
//Remove o primeiro elemento da fila F.
void RemoveFila(Fila *pF){
    if(pF->vazia == 1 ) {
        Underflow();
        exit(1) ;
    }
    else {
        pF->inicio = (pF->inicio + 1) % MAX;
        /* O novo inicio passou do fim? */
        if (pF->inicio == (pF->fim + 1) % MAX)
            pF->vazia = 1;
    }
}
Exemple #12
0
void llist::deleteRear(el_t& Old)
{
        // case(exception)
        // ---------------
        if(isEmpty())
          throw Underflow();

        // case(list will empty)
        // ------------------------------
        // retrieve the number
        // delete the Rear (also the Front)
        // Front and Rear point to NULL
        // decrement Count

        else if(Front->Next == NULL && Rear->Next == NULL)
        {
          Old = Rear->Elem;
          delete Rear;
          Front = NULL;
          Rear = NULL;
          Count--;
        }

        // case(regular)
        // -------------
        // create a temp pointer to go from the top to the
        // node before the rear. retrieve the rear's number
        // delete rear and rear will point to temp, which
        // will point to NULL
        else
        {
          Node *temp = Front;

          while(temp->Next->Next != NULL)
            temp = temp->Next;

          Old = Rear->Elem;
          delete Rear;
          Rear = temp;
          Rear->Next = NULL;
          Count--;
        }
}
Exemple #13
0
void llist::deleteFront(el_t& Old)
{
          // case(exception)
          // ---------------
          if(isEmpty())
            throw Underflow();

          // case(only one node in the list)
          // -------------------------------
          // obtain the number fron the front
          // delete front
          // point front and rear to NULL
          // decrement count
          else if(Front->Next == NULL && Rear->Next == NULL)
          {
            Old = Front->Elem;
            delete Front;
            Front = NULL;
            Rear = NULL;
            Count--;
          }

          // case(regular)
          // -------------
          // obtain the number from the front
          // create a temp pointer which points to front
          // move to the pointer to the next node
          // delete front
          // move front to temp, making the new front
          // decrement count
          else
          {
            Old = Front->Elem;
            Node *temp = Front;
            temp = temp->Next;
            delete Front;
            Front = temp;
            Count--;
          }
}
Exemple #14
0
template <class T> T 
AQueue<T>::dequeue (void)
{
  if (!is_empty()){

    /*
    You can just say
    T &tmp = queue_[head_];
    which is more efficient.
    */

    //My response: replace T tmp = queue_[head_] 
    //              with T &tmp = queue_[head_];

    T &tmp = queue_[head_];
    head_ = increment(head_);
    count_--;
    return tmp;
  }
  else
    throw Underflow();
}
Exemple #15
0
 const Comparable & BinaryHeap<Comparable>::findMin( ) const
 {
     if( isEmpty( ) )
         throw Underflow( );
     return array[ 1 ];
 }
Exemple #16
0
 const Object & QueueLL<Object>::getFront( ) const
 {
     if( isEmpty( ) )
         throw Underflow( );
     return head->element;
 }
 const Object & Stack<Object>::top( ) const
 {
     if( isEmpty( ) )
         throw Underflow( );
     return topOfStack->element;
 }
Exemple #18
0
const Object & Queue<Object>::getFront( ) const
{
    if( isEmpty( ) )
        throw Underflow( );
    return theArray[ front ];
}