-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathheader
53 lines (41 loc) · 1.07 KB
/
header
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
#ifndef PAIRINGHEAP_H
#define PAIRINGHEAP_H
#include <string>
using namespace std;
struct PairNode{
string name;
int value;
PairNode *leftChild;
PairNode *sibling;
PairNode():
leftChild(NULL), sibling(NULL) {}
PairNode(string name1, int value1, PairNode *leftChild1, PairNode *sibling1):
name(name1), value(value1), leftChild(leftChild1), sibling(sibling1) {}
void addChild(PairNode *node){
if (leftChild == NULL){
leftChild = node;
} else {
node->sibling = leftChild;
leftChild = node;
}
}
};
class PairingHeap{
public:
//constructor
PairingHeap();
//destuctor
~PairingHeap();
bool isEmpty() const;
void insert(string name, int value);
PairNode peek() const;
PairNode *remove();
void printOut() const;
void deleteAll(PairNode *node);
private:
PairNode *origin;
int logicalSize;
PairNode *mergeTrees(PairNode *first, PairNode *second);
PairNode *mergeSiblings(PairNode *node);
};
#endif // PAIRINGHEAP_H