-
Notifications
You must be signed in to change notification settings - Fork 0
/
rb_tree_node.hh
126 lines (101 loc) · 2.52 KB
/
rb_tree_node.hh
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#ifndef RB_NODE_HH
#define RB_NODE_HH
#include "tree_node.hh"
// colorile posibile pentru un nod
enum NodeColor
{
RED = 0,
BLACK = 1
};
template <class T>
class RedBlackTreeNode : public TreeNode<T>
{
// culoarea nodului;
NodeColor color;
public:
RedBlackTreeNode();
RedBlackTreeNode(T x);
RedBlackTreeNode(T x, NodeColor color);
RedBlackTreeNode(const RedBlackTreeNode<T> &node);
RedBlackTreeNode(const TreeNode<T> &node);
// returneaza nodul parinte;
const RedBlackTreeNode<T> *get_parent() const;
// returneaza copilul stang;
const RedBlackTreeNode<T> *get_left() const;
// returneaza copilul drept;
const RedBlackTreeNode<T> *get_right() const;
// returneaza culoarea nodului;
NodeColor get_color() const;
// seteaza culoarea nodului;
void set_color(NodeColor color);
RedBlackTreeNode<T> &operator=(const RedBlackTreeNode<T> &node);
RedBlackTreeNode<T> &operator=(T x);
};
template <class T>
const RedBlackTreeNode<T> *RedBlackTreeNode<T>::get_parent() const
{
return (RedBlackTreeNode<T> *)this->p;
}
template <class T>
const RedBlackTreeNode<T> *RedBlackTreeNode<T>::get_left() const
{
return (RedBlackTreeNode<T> *)this->left;
}
template <class T>
const RedBlackTreeNode<T> *RedBlackTreeNode<T>::get_right() const
{
return (RedBlackTreeNode<T> *)this->right;
}
template <class T>
RedBlackTreeNode<T>::RedBlackTreeNode() : TreeNode<T>()
{
this->color = RED;
}
template <class T>
RedBlackTreeNode<T>::RedBlackTreeNode(T x) : TreeNode<T>(x)
{
this->color = RED;
}
template <class T>
RedBlackTreeNode<T>::RedBlackTreeNode(T x, NodeColor color) : TreeNode<T>(x)
{
this->color = color;
}
template <class T>
RedBlackTreeNode<T>::RedBlackTreeNode(const RedBlackTreeNode<T> &node) : TreeNode<T>(node)
{
this->color = node.color;
}
template <class T>
RedBlackTreeNode<T>::RedBlackTreeNode(const TreeNode<T> &node) : TreeNode<T>(node)
{
this->color = RED;
}
template <class T>
NodeColor RedBlackTreeNode<T>::get_color() const
{
return this->color;
}
template <class T>
void RedBlackTreeNode<T>::set_color(NodeColor color)
{
this->color = color;
}
template <class T>
RedBlackTreeNode<T> &RedBlackTreeNode<T>::operator=(const RedBlackTreeNode<T> &node)
{
TreeNode<T>::operator=(node);
if (this != &node)
{
this->color = node.color;
}
return *this;
}
template <class T>
RedBlackTreeNode<T> &RedBlackTreeNode<T>::operator=(T x)
{
TreeNode<T>::operator=(x);
this->color = RED;
return *this;
}
#endif