-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.cpp
More file actions
82 lines (63 loc) · 1.19 KB
/
Node.cpp
File metadata and controls
82 lines (63 loc) · 1.19 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "Node.h"
// ==========
// Accessors
// ==========
string Node::getKey() const {
return key;
}
int Node::getCount() const {
return count;
}
Node* Node::getLeft() const {
return leftSubtree;
}
Node* Node::getRight() const {
return rightSubtree;
}
int Node::getHeight() const {
return height;
}
// ==========
// Mutators
// ==========
void Node::copyFrom(Node *node) {
key = node->getKey();
count = node->getCount();
}
void Node::incrementCount() {
count++;
}
void Node::decrementCount() {
count--;
}
void Node::setLeft(Node *node) {
leftSubtree = node;
}
void Node::setRight(Node *node) {
rightSubtree = node;
}
void Node::deleteLeft() {
leftSubtree = 0;
}
void Node::deleteRight() {
rightSubtree = 0;
}
void Node::incrementHeight() {
++height;
}
void Node::setParent(Node *node) {
parent = node;
}
// ==========[]
// Comparators
// ==========
bool Node::operator==(const Node &node) {
return node.getKey() == key;
}
// ==========
// Printing
// ==========
ostream& operator<<(ostream &out, const Node &node) {
out << node.key << "(" << node.count << ")";
return out;
}