Switch to **
parent
5d76457678
commit
db27eae97b
|
@ -61,7 +61,7 @@ namespace blt {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BST_node* search(BST_node*& parent, const T& element) const {
|
BST_node* search(BST_node** parent, const T& element) const {
|
||||||
BST_node* searchNode = m_root;
|
BST_node* searchNode = m_root;
|
||||||
// basically we are iterating through the tree looking for a valid node to insert into.
|
// basically we are iterating through the tree looking for a valid node to insert into.
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -69,12 +69,12 @@ namespace blt {
|
||||||
return searchNode->payload;
|
return searchNode->payload;
|
||||||
// check for left and right tree traversal if it exists
|
// check for left and right tree traversal if it exists
|
||||||
if (searchNode->left != nullptr && element < searchNode->left->payload) {
|
if (searchNode->left != nullptr && element < searchNode->left->payload) {
|
||||||
parent = searchNode;
|
*parent = searchNode;
|
||||||
searchNode = searchNode->left;
|
searchNode = searchNode->left;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (searchNode->right != nullptr && element > searchNode->right->payload) {
|
if (searchNode->right != nullptr && element > searchNode->right->payload) {
|
||||||
parent = searchNode;
|
*parent = searchNode;
|
||||||
searchNode = searchNode->right;
|
searchNode = searchNode->right;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -113,13 +113,12 @@ namespace blt {
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] inline BST_node* search(const T& element) const {
|
[[nodiscard]] inline BST_node* search(const T& element) const {
|
||||||
BST_node parent;
|
return search(nullptr, element);
|
||||||
return search(&parent, element);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void remove(const T& element) {
|
void remove(const T& element) {
|
||||||
BST_node* parent {};
|
BST_node* parent {};
|
||||||
BST_node* elementNode = search(parent, element);
|
BST_node* elementNode = search(&parent, element);
|
||||||
|
|
||||||
BST_node*& parentChildSide = parent->left;
|
BST_node*& parentChildSide = parent->left;
|
||||||
if (parent->right == elementNode)
|
if (parent->right == elementNode)
|
||||||
|
@ -136,7 +135,6 @@ namespace blt {
|
||||||
delete(node);
|
delete(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
parentChildSide = elementNode->left != nullptr ? elementNode->left : elementNode->right;
|
parentChildSide = elementNode->left != nullptr ? elementNode->left : elementNode->right;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue