Fix null issue

v1
Brett 2023-01-10 22:32:14 -05:00
parent 15eaf59503
commit 6a2a5948fb
1 changed files with 4 additions and 2 deletions

View File

@ -71,12 +71,14 @@ namespace blt {
return nullptr; return nullptr;
// 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; if (parent != nullptr)
*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; if (parent != nullptr)
*parent = searchNode;
searchNode = searchNode->right; searchNode = searchNode->right;
continue; continue;
} }