{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# BinomialQueue - package DataStructures BinomialQueue class...

This preview shows pages 1–2. Sign up to view the full content.

package DataStructures; // BinomialQueue class // // CONSTRUCTION: with a negative infinity sentinel // // ******************PUBLIC OPERATIONS********************* // void insert( x ) --> Insert x // Comparable deleteMin( )--> Return and remove smallest item // Comparable findMin( ) --> Return smallest item // boolean isEmpty( ) --> Return true if empty; else false // boolean isFull( ) --> Return true if full; else false // void makeEmpty( ) --> Remove all items // vod merge( rhs ) --> Absord rhs into this heap // ******************ERRORS******************************** // Overflow if CAPACITY is exceeded /** * Implements a binomial queue. * Note that all "matching" is based on the compareTo method. * @author Mark Allen Weiss */ public class BinomialQueue { /** * Construct the binomial queue. */ public BinomialQueue( ) { theTrees = new BinomialNode[ MAX_TREES ]; makeEmpty( ); } /** * Merge rhs into the priority queue. * rhs becomes empty. rhs must be different from this. * @param rhs the other binomial queue. * @exception Overflow if result exceeds capacity. */ public void merge( BinomialQueue rhs ) throws Overflow { if( this == rhs ) // Avoid aliasing problems return; if( currentSize + rhs.currentSize > capacity( ) ) throw new Overflow( ); currentSize += rhs.currentSize; BinomialNode carry = null; for( int i = 0, j = 1; j <= currentSize; i++, j *= 2 ) { BinomialNode t1 = theTrees[ i ]; BinomialNode t2 = rhs.theTrees[ i ]; int whichCase = t1 == null ? 0 : 1;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}