30 #ifndef DOXYGEN_SHOULD_SKIP_THIS 34 template <
typename Val >
45 template <
typename Val >
56 template <
typename Val >
80 template <
typename Val >
82 operator=(
const BinTreeNode< Val >& from) {
92 template <
typename Val >
97 template <
typename Val >
102 template <
typename Val >
104 return _children[
static_cast< int >(dir)];
107 template <
typename Val >
112 template <
typename Val >
117 template <
typename Val >
122 template <
typename Val >
127 template <
typename Val >
129 if (new_child._parent) {
130 GUM_ERROR(DuplicateElement,
"this child already has a parent in the BST");
134 GUM_ERROR(DuplicateElement,
"this child already has a parent in the BST");
138 new_child._parent =
this;
143 template <
typename Val >
146 GUM_ERROR(DuplicateElement,
"this child already has a parent in the BST");
149 BinTreeNode< Val >* new_child =
new BinTreeNode< Val >(val);
152 new_child->_parent =
this;
159 template <
typename Val >
161 if (new_child._parent) {
162 GUM_ERROR(DuplicateElement,
"this child already has a parent in the BST");
166 GUM_ERROR(DuplicateElement,
"this node already has a right child");
170 new_child._parent =
this;
175 template <
typename Val >
178 GUM_ERROR(DuplicateElement,
"this node already has a right child");
181 BinTreeNode< Val >* new_child =
new BinTreeNode< Val >(val);
184 new_child->_parent =
this;
191 template <
typename Val >
194 if (new_child._parent) {
195 GUM_ERROR(DuplicateElement,
"this child has already a parent");
198 if (
_children[static_cast< int >(child_dir)]) {
199 GUM_ERROR(DuplicateElement,
"this node has already this child");
203 new_child._parent =
this;
204 new_child._parent_dir = child_dir;
205 _children[
static_cast< int >(child_dir)] = &new_child;
208 template <
typename Val >
209 INLINE BinTreeNode< Val >*
211 if (
_children[static_cast< int >(child_dir)]) {
212 GUM_ERROR(DuplicateElement,
"this node has already this child");
215 BinTreeNode< Val >* new_child =
new BinTreeNode< Val >(val);
218 new_child->_parent =
this;
219 new_child->_parent_dir = child_dir;
220 _children[
static_cast< int >(child_dir)] = new_child;
225 template <
typename Val >
235 template <
typename Val >
245 template <
typename Val >
247 if (
_children[static_cast< int >(tree_dir)]) {
250 _children[
static_cast< int >(tree_dir)] =
nullptr;
254 template <
typename Val >
256 BinTreeNode< Val >* node =
const_cast< BinTreeNode< Val >*
>(
this);
264 template <
typename Val >
266 BinTreeNode< Val >* node =
const_cast< BinTreeNode< Val >*
>(
this);
274 template <
typename Val >
276 BinTreeNode< Val >* node =
const_cast< BinTreeNode< Val >*
>(
this);
278 while (node->_parent)
279 node = node->_parent;
286 #endif // DOXYGEN_SHOULD_SKIP_THIS BinTreeNode< Val > * child(BinTreeDir dir) const
Returns the given child of a node.
Val & value()
Returns the value stored in a node of the binary search tree.
BinTreeNode< Val > * leftmostNode() const
Returns the leftmost node of the current tree.
Val _val
The value stored in a node of the tree.
BinTreeNode< Val > * insertLeftChild(const Val &val)
Adds a new left child to the current node.
void eraseLeftLink()
Remove the link between the current node and its left child.
BinTreeNode< Val > * leftChild() const
Returns the given child of a node.
BinTreeNode< Val > * _children[2]
The children of the current node.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
BinTreeNode(const Val &v)
Basic constructor: a node without parent nor children.
void eraseLink(BinTreeDir tree_dir)
Remove the link between the current node and one of its children.
BinTreeDir
The direction of a given edge in a binary tree.
BinTreeNode< Val > & operator=(const BinTreeNode< Val > &from)
Copy operator: copy the value of from into this.
BinTreeNode< Val > * rightmostNode() const
Returns the rightmost node of the current tree.
BinTreeDir _parent_dir
the direction to follow from the parent to reach the current node.
void eraseRightLink()
Remove the link between the current node and its right child.
BinTreeDir parentDir() const
Returns the direction of the edge parent->current node, if any.
BinTreeNode< Val > * root() const
Returns the top ancestor of the current tree.
BinTreeNode< Val > * rightChild() const
Returns the given child of a node.
BinTreeNode< Val > * parent() const
Returns the parent of a node.
Val & operator*()
Alias for method value.
BinTreeNode< Val > * _parent
The parent of the node.
BinTreeNode< Val > * insertRightChild(const Val &val)
Adds a new left child to the current node.
~BinTreeNode()
Class destructor.
#define GUM_ERROR(type, msg)
BinTreeNode< Val > * insertChild(const Val &val, BinTreeDir child_dir)
Adds a new child to the current node.