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; }
void deleteMin(void) { if(isEmpty()) throw UnderflowException(); array[i]=array[currentSize--]; percolateDown(1); }
void deleteMin(Comparable& minItem) { if(isEmpty()) throw UnderflowException(); minItem=array[1]; array[1]=array[currentSize--]; percolateDown(1); }
void Stack<Object>::pop( ) { if( isEmpty( ) ) throw UnderflowException( ); ListNode *oldTop = topOfStack; topOfStack = topOfStack->next; delete oldTop; }
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; }
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; }
const Object & priority_queue<Object,Container,Compare>::top( ) const { if( empty( ) ) throw UnderflowException( "Cannot top an empty priority queue" ); return theItems[ 1 ]; }
const Object & Stack<Object>::top( ) const { if( isEmpty( ) ) throw UnderflowException( ); return topOfStack->element; }
huffmanNode* heap::findMin() const { if(isEmpty()) throw UnderflowException(); return array[1]; }