-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.h
More file actions
66 lines (46 loc) · 1.47 KB
/
Node.h
File metadata and controls
66 lines (46 loc) · 1.47 KB
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
#ifndef HUFFMAN_NODE_H
#define HUFFMAN_NODE_H
#include <memory>
using namespace std;
class Node {
public:
char character; // The actual character (like 'A', 'B', etc.)
int frequency; // How many times this character appears
shared_ptr<Node> left; // Pointer to left child (for Huffman tree)
shared_ptr<Node> right; // Pointer to right child (for Huffman tree)
// --- Constructors ---
// Constructor: sets both character and frequency
Node(char ch, int freq)
: character(ch), frequency(freq), left(nullptr), right(nullptr) {}
// Constructor: sets only character, frequency becomes 0
explicit Node(char ch)
: character(ch), frequency(0), left(nullptr), right(nullptr) {}
// --- Getter Functions ---
// Get frequency value
int getFrequency() const {
return frequency;
}
// Get character value
char getCharacter() const {
return character;
}
// --- Setter Functions (for child connections) ---
// Connect left child node
void setLeft(shared_ptr<Node> l) {
left = l;
}
// Connect right child node
void setRight(shared_ptr<Node> r) {
right = r;
}
// --- Getter Functions (for child access) ---
// Get left child node
shared_ptr<Node> getLeft() const {
return left;
}
// Get right child node
shared_ptr<Node> getRight() const {
return right;
}
};
#endif