-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.cpp
50 lines (43 loc) · 905 Bytes
/
Node.cpp
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
#include "Node.hpp"
using namespace std;
Node::Node() {
data = 0xFF;
frequency = 0;
encoded_data = "";
left = nullptr;
right = nullptr;
internal_node = nullptr;
}
Node::Node(const uint8_t &d, const int &f){
data = d;
frequency = f;
encoded_data = "";
left = nullptr;
right = nullptr;
internal_node = nullptr;
}
Node::Node(const Node & param){
data = param.data;
frequency = param.frequency;
encoded_data = param.encoded_data;
left = param.left;
right = param.right;
internal_node = param.internal_node;
}
Node Node::operator + (Node & r) {
Node temp;
temp.frequency = frequency + r.frequency;
temp.data = 0xFF;
temp.left = this;
temp.right = &r;
return temp;
}
int Node::compare(const Node &r) const
{
int lf = this->get_frequency();
int rf = r.get_frequency();
// if lf < rf, return negative
// if lf > rf, return positive
// if lf == rf, return 0
return (lf-rf);
}