-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaxHeap.h
57 lines (40 loc) · 1.24 KB
/
MaxHeap.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
//Kanellaki Maria Anna - 1115201400060
#ifndef MAXHEAP_H
#define MAXHEAP_H
#include <string>
#include "Queue.h"
using namespace std;
class HeapNode { //represents a node of the max heap. contains a key and the count of diseased people for that key
string key; //country or disease
int count;
HeapNode * parent;
HeapNode * right;
HeapNode * left;
public:
HeapNode(string, int);
~HeapNode();
void SwapNodeData(HeapNode*);
int getCount() const;
const string &getKey() const;
void setCount(int count);
HeapNode *getRight() const;
HeapNode *getLeft() const;
void setRight(HeapNode *right);
void setLeft(HeapNode *left);
HeapNode *getParent() const;
void setParent(HeapNode *parent);
};
class MaxHeap { //represents a dynamic approach of a max binary heap
HeapNode * root;
Queue * incompleteNodes; //stores all heap nodes that do not have 2 children. helps keep the heap complete
public:
MaxHeap();
void insertNode(HeapNode*);
void heapify(HeapNode*);
void PrintTopK(int, string);
void Exists(HeapNode*, string, HeapNode**);
void destroyHeap(HeapNode*);
~MaxHeap();
HeapNode *getRoot() const;
};
#endif