Source of HeapInterface.h


  1: //  Created by Frank M. Carrano and Tim Henry.
  2: //  Copyright (c) 2013 __Pearson Education__. All rights reserved.

  4: /** Interface for the ADT heap.
  5:     Listing 17-1.
  6:  @file HeapInterface.h */

  8: #ifndef _HEAP_INTERFACE
  9: #define _HEAP_INTERFACE

 11: template<class ItemType>
 12: class HeapInterface
 13: {
 14: public:
 15:    /** Sees whether this heap is empty.
 16:     @return True if the heap is empty, or false if not. */
 17:    virtual bool isEmpty() const = 0;
 18:    
 19:    /** Gets the number of nodes in this heap.
 20:     @return The number of nodes in the heap. */
 21:    virtual int getNumberOfNodes() const = 0;
 22:    
 23:    /** Gets the height of this heap.
 24:     @return The height of the heap. */
 25:    virtual int getHeight() const = 0;
 26:    
 27:    /** Gets the data that is in the root (top) of this heap.
 28:     For a maxheap, the data is the largest value in the heap;
 29:     for a minheap, the data is the smallest value in the heap.
 30:     @pre The heap is not empty.
 31:     @post The root’s data has been returned, and the heap is unchanged.
 32:     @return The data in the root of the heap. */
 33:    virtual ItemType peekTop() const = 0;
 34:    
 35:    /** Adds a new node containing the given data to this heap.
 36:     @param newData The data for the new node.
 37:     @post The heap contains a new node.
 38:     @return True if the addition is successful, or false if not. */
 39:    virtual bool add(const ItemType& newData) = 0;
 40:    
 41:    /** Removes the root node from this heap.
 42:     @return True if the removal is successful, or false if not. */
 43:    virtual bool remove() = 0;
 44:    
 45:    /** Removes all nodes from this heap. */
 46:    virtual void clear() = 0;
 47: }; // end HeapInterface
 48: #endif