PairHeap - package DataStructures; / / / / / / / / / / / /...

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

View Full Document Right Arrow Icon
package DataStructures; // PairHeap class // // CONSTRUCTION: with no initializer // // ******************PUBLIC OPERATIONS********************* // PairNode insert( x ) --> Insert x, return position // Comparable deleteMin( )--> Return and remove smallest item // Comparable findMin( ) --> Return smallest item // boolean isEmpty( ) --> Return true if empty; else false // void makeEmpty( ) --> Remove all items // void decreaseKey( PairNode p, newVal ) // --> Decrease value in node p /** * Implements a pairing heap. * Supports a decreaseKey operation. * Note that all "matching" is based on the compareTo method. * @author Mark Allen Weiss * @see PairNode */ public class PairHeap { /** * Construct the pairing heap. */ public PairHeap( ) { root = null; } /** * Insert into the priority queue, and return a PairNode * that can be used by decreaseKey. * Duplicates are allowed. * @param x the item to insert. * @return the node containing the newly inserted item. */ public PairNode insert( Comparable x ) { PairNode newNode = new PairNode( x ); if( root == null ) root = newNode; else root = compareAndLink( root, newNode ); return newNode; } /** * Find the smallest item in the priority queue. * @return the smallest item, or null if empty. */ public Comparable findMin( ) { if( isEmpty( ) ) return null; return root.element;
Background image of page 1

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

View Full DocumentRight Arrow Icon
} /** * Remove the smallest item from the priority queue. * @return the smallest item, or null if empty.
Background image of page 2
Image of page 3
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

PairHeap - package DataStructures; / / / / / / / / / / / /...

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

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