From 15eaf59503cc3b5a80b74c9caf3210e887bcf2e3 Mon Sep 17 00:00:00 2001 From: Brett Date: Tue, 10 Jan 2023 22:30:54 -0500 Subject: [PATCH] Fix search infinite loop on not foundo --- include/blt/std/binary_tree.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/blt/std/binary_tree.h b/include/blt/std/binary_tree.h index a070f81..1d08e67 100644 --- a/include/blt/std/binary_tree.h +++ b/include/blt/std/binary_tree.h @@ -67,6 +67,8 @@ namespace blt { while (true) { if (searchNode->payload == element) return searchNode; + if (searchNode->left == nullptr && searchNode->right == nullptr) + return nullptr; // check for left and right tree traversal if it exists if (searchNode->left != nullptr && element < searchNode->left->payload) { *parent = searchNode;