Fix insert?
parent
21aa7ed6ac
commit
33ee1f2dc7
|
@ -47,11 +47,11 @@ namespace blt {
|
||||||
if (element == searchNode->payload)
|
if (element == searchNode->payload)
|
||||||
throw binary_search_tree_error{"Unable to insert. Nodes cannot have equal values!\n"};
|
throw binary_search_tree_error{"Unable to insert. Nodes cannot have equal values!\n"};
|
||||||
// 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->payload) {
|
||||||
searchNode = searchNode->left;
|
searchNode = searchNode->left;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (searchNode->right != nullptr && element > searchNode->right->payload) {
|
if (searchNode->right != nullptr && element > searchNode->payload) {
|
||||||
searchNode = searchNode->right;
|
searchNode = searchNode->right;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue