BinomialQueue - package DataStructures; / / / / / / / / / /...

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

View Full Document Right Arrow Icon
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 ];
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/22/2011 for the course CSC 532 taught by Professor Dr.gursaranadhar during the Spring '07 term at University of North Carolina Wilmington.

Page1 / 5

BinomialQueue - package DataStructures; / / / / / / / / / /...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online