-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBinomialQueue.h
75 lines (61 loc) · 2.67 KB
/
BinomialQueue.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef BINOMIAL_QUEUE_H_
#define BINOMIAL_QUEUE_H_
#include <iostream.h>
#include "vector.h"
// Binomial queue class
//
// CONSTRUCTION: with no parameters
//
// ******************PUBLIC OPERATIONS*********************
// void insert( x ) --> Insert x
// deleteMin( ) --> Return and remove 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
// void merge( rhs ) --> Absorb rhs into this heap
// ******************ERRORS********************************
// Throws Underflow and Overflow as warranted
// Node and forward declaration because g++ does
// not understand nested classes.
template <class Comparable>
class BinomialQueue;
template <class Comparable>
class BinomialNode
{
Comparable element;
BinomialNode *leftChild;
BinomialNode *nextSibling;
BinomialNode( const Comparable & theElement,
BinomialNode *lt, BinomialNode *rt )
: element( theElement ), leftChild( lt ), nextSibling( rt ) { }
friend class BinomialQueue<Comparable>;
};
template <class Comparable>
class BinomialQueue
{
public:
BinomialQueue( );
BinomialQueue( const BinomialQueue & rhs );
~BinomialQueue( );
bool isEmpty( ) const;
bool isFull( ) const;
const Comparable & findMin( ) const;
void insert( const Comparable & x );
void deleteMin( );
void deleteMin( Comparable & minItem );
void makeEmpty( );
void merge( BinomialQueue & rhs );
const BinomialQueue & operator=( const BinomialQueue & rhs );
private:
int currentSize; // Number of items in the priority queue
vector<BinomialNode<Comparable> *> theTrees; // An array of tree roots
int findMinIndex( ) const;
int capacity( ) const;
BinomialNode<Comparable> * combineTrees( BinomialNode<Comparable> *t1,
BinomialNode<Comparable> *t2 ) const;
void makeEmpty( BinomialNode<Comparable> * & t ) const;
BinomialNode<Comparable> * clone( BinomialNode<Comparable> * t ) const;
};
#include "BinomialQueue.cpp"
#endif