-
Notifications
You must be signed in to change notification settings - Fork 0
/
priorities.h
62 lines (44 loc) · 1.36 KB
/
priorities.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
#include <string>
#include <vector>
using namespace std;
class Heap {
private:
struct Node {
unsigned int priority;
string data;
};
vector<Node> content;
void swap(Node &n1, Node &n2){
Node tmp;
tmp.data = n2.data;
tmp.priority = n2.priority;
n2.data = n1.data;
n2.priority = n1.priority;
n1.data = tmp.data;
n1.priority = tmp.priority;
}
size_t lengthOfContent(unsigned long) const;
void heapifyUp(unsigned long);
void heapifyDown(unsigned long);
public:
Heap() {} //default constructor
Heap(const vector<string> &); //Heap from array
Heap(const Heap&); //copy constructor
Heap(istream &); //constructor that reads all words from a file
string top() const { return (content.empty()) ? "" : content[0].data; }
bool has(string s) const {
for(auto &n : content) {
if(n.data == s) return true;
}
return false;
}
bool empty() const { return content.empty(); }
void push(string, unsigned int);
string pop();
vector<string> printLinear() const;
unsigned int operator[](string) const;
Heap & operator+=(const Heap&);
friend ostream &operator<<(ostream &, const Heap&);
};
// Question 2
ostream &operator<<(ostream &, const Heap& h);