#ifndef BINARY_HEAP_H #define BINARY_HEAP_H #include using namespace std; // 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 // void makeEmpty( ) --> Remove all items template class BinaryHeap { public: explicit BinaryHeap( int capacity = 100 ) : array( capacity + 1 ), currentSize{ 0 } { } explicit BinaryHeap( const vector & items ) : array( items.size( ) + 10 ), currentSize{ items.size( ) } { for( int i = 0; i < items.size( ); ++i ) array[ i + 1 ] = items[ i ]; buildHeap( ); } bool isEmpty( ) const { } /** * Find the smallest item in the priority queue. * Return the smallest item. */ const Comparable & findMin( ) const { } /** * Insert item x, allowing duplicates. */ void insert( const Comparable & x ) { } /** * Remove the minimum item. */ void deleteMin( ) { } /** * Remove the minimum item and place it in minItem. */ void deleteMin( Comparable & minItem ) { } void makeEmpty( ) { currentSize = 0; } private: int currentSize; // Number of elements in heap vector array; // The heap array /** * Establish heap order property from an arbitrary * arrangement of items. Runs in linear time. */ void buildHeap( ) { for( int i = currentSize / 2; i > 0; --i ) percolateDown( i ); } /** * Internal method to percolate down in the heap. * hole is the index at which the percolate begins. */ void percolateDown( int hole ) { } }; #endif