-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBinaryHeap.h
46 lines (38 loc) · 1.58 KB
/
BinaryHeap.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef _BINARY_HEAP_H_
#define _BINARY_HEAP_H_
#include "dsexceptions.h"
#include "vector.h"
// BinaryHeap class
//
// CONSTRUCTION: with a negative infinity sentinel and
// 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 Comparable>
class BinaryHeap
{
public:
explicit BinaryHeap( int capacity = 511 );
bool isEmpty( ) const;
bool isFull( ) const;
const Comparable & findMin( ) const;
void insert( const Comparable & x );
void deleteMin( );
void deleteMin( Comparable & minItem );
void makeEmpty( );
int currentSize; // Number of elements in heap
private:
vector<Comparable> array; // The heap array
void buildHeap( );
void percolateDown( int hole );
};
#include "BinaryHeap.cpp"
#endif