From db27eae97b624f425bd03f4a3eabe83a4b5a4de3 Mon Sep 17 00:00:00 2001 From: Brett Date: Tue, 10 Jan 2023 22:28:32 -0500 Subject: [PATCH] Switch to ** --- include/blt/std/binary_tree.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/include/blt/std/binary_tree.h b/include/blt/std/binary_tree.h index 6598279..804b1bf 100644 --- a/include/blt/std/binary_tree.h +++ b/include/blt/std/binary_tree.h @@ -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; // basically we are iterating through the tree looking for a valid node to insert into. while (true) { @@ -69,12 +69,12 @@ namespace blt { return searchNode->payload; // check for left and right tree traversal if it exists if (searchNode->left != nullptr && element < searchNode->left->payload) { - parent = searchNode; + *parent = searchNode; searchNode = searchNode->left; continue; } if (searchNode->right != nullptr && element > searchNode->right->payload) { - parent = searchNode; + *parent = searchNode; searchNode = searchNode->right; continue; } @@ -113,13 +113,12 @@ namespace blt { } [[nodiscard]] inline BST_node* search(const T& element) const { - BST_node parent; - return search(&parent, element); + return search(nullptr, element); } void remove(const T& element) { BST_node* parent {}; - BST_node* elementNode = search(parent, element); + BST_node* elementNode = search(&parent, element); BST_node*& parentChildSide = parent->left; if (parent->right == elementNode) @@ -136,7 +135,6 @@ namespace blt { delete(node); } } - } else { parentChildSide = elementNode->left != nullptr ? elementNode->left : elementNode->right; }