Binary Heap Class
Binary Heap Class
#ifndef _BINARY_HEAP_H_
#define _BINARY_HEAP_H_
#include "dsexceptions.h"
#include "vector.h"
// BinaryHeap class
//
// CONSTRUCTION: with an optional capacity (that defaults to 100)
//
// ******************PUBLIC OPERATIONS*********************
// void insert( x ) --> Insert x
// deleteMin( minItem ) --> Remove (and optionally return) smallest item
// Comparable findMin( ) --> Return smallest item
// bool isEmpty( ) --> Return true if empty; else false
// bool isFull( ) --> Return true if full; else false
// void makeEmpty( ) --> Remove all items
// ******************ERRORS********************************
// Throws Underflow and Overflow as warranted
template
class BinaryHeap
{
public:
explicit BinaryHeap( int capacity = 100 );
bool isEmpty( ) const;
bool isFull( ) const;
const Comparable & findMin( ) const;
void insert( const Comparable & x );
void deleteMin( );
void deleteMin( Comparable & minItem );
void makeEmpty( );
private:
int currentSize; // Number of elements in heap
vector array; // The heap array
void buildHeap( );
void percolateDown( int hole );
};
#endif
Tuesday, 11-Apr-2000 16:03:48 EDT
Sorry! We could not find what you were looking for
Try going back to the main page here
Sorry! We could not find what you were looking for
Try going back to the main page here