-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathred_black_tree_node.hpp
More file actions
92 lines (75 loc) · 2.61 KB
/
red_black_tree_node.hpp
File metadata and controls
92 lines (75 loc) · 2.61 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
83
84
85
86
87
88
89
90
91
92
#ifndef RED_BLACK_TREE_NODE_HPP
#define RED_BLACK_TREE_NODE_HPP
namespace ft {
enum Color {
RED,
BLACK,
DUB_BLACK
};
template <typename T>
struct RedBlackTreeNode {
T value;
Color color;
RedBlackTreeNode *left;
RedBlackTreeNode *right;
RedBlackTreeNode *parent;
RedBlackTreeNode() : value(), color(RED), left(NULL), right(NULL), parent(NULL) {}
// RedBlackTreeNode(const T &value) : value(value), color(RED), left(NULL), right(NULL), parent(NULL) {}
RedBlackTreeNode(const T &value, Color color = RED, RedBlackTreeNode *left = NULL, RedBlackTreeNode *right = NULL, RedBlackTreeNode *parent = NULL) : value(value), color(color), left(left), right(right), parent(parent) {}
RedBlackTreeNode(const RedBlackTreeNode &other) : value(other.value), color(other.color), left(other.left), right(other.right), parent(other.parent) {}
~RedBlackTreeNode() {}
RedBlackTreeNode &operator=(const RedBlackTreeNode &other) {
if (this != &other) {
value = other.value;
color = other.color;
left = other.left;
right = other.right;
parent = other.parent;
}
return *this;
}
bool operator==(const RedBlackTreeNode &other) const {
return value == other.value;
}
bool operator!=(const RedBlackTreeNode &other) const {
return value != other.value;
}
// bool operator<(const RedBlackTreeNode &other) const {
// return value < other.value;
// }
// bool operator<=(const RedBlackTreeNode &other) const {
// return value <= other.value;
// }
// bool operator>(const RedBlackTreeNode &other) const {
// return value > other.value;
// }
// bool operator>=(const RedBlackTreeNode &other) const {
// return value >= other.value;
// }
};
template <class T1, class T2>
bool operator==(const RedBlackTreeNode<T1> &lhs, const RedBlackTreeNode<T2> &rhs) {
return lhs == rhs;
}
template <class T1, class T2>
bool operator!=(const RedBlackTreeNode<T1> &lhs, const RedBlackTreeNode<T2> &rhs) {
return lhs != rhs;
}
// template <class T1, class T2>
// bool operator<(const RedBlackTreeNode<T1> &lhs, const RedBlackTreeNode<T2> &rhs) {
// return lhs.value < rhs.value;
// }
// template <class T1, class T2>
// bool operator<=(const RedBlackTreeNode<T1> &lhs, const RedBlackTreeNode<T2> &rhs) {
// return lhs.value <= rhs.value;
// }
// template <class T1, class T2>
// bool operator>(const RedBlackTreeNode<T1> &lhs, const RedBlackTreeNode<T2> &rhs) {
// return lhs.value > rhs.value;
// }
// template <class T1, class T2>
// bool operator>=(const RedBlackTreeNode<T1> &lhs, const RedBlackTreeNode<T2> &rhs) {
// return lhs.value >= rhs.value;
// }
};
#endif