From d50ed323fdaa07301edceb02069e62730df962a4 Mon Sep 17 00:00:00 2001 From: bt3gl <138340846+bt3gl-cryptographer@users.noreply.github.com> Date: Tue, 8 Aug 2023 15:35:17 -0700 Subject: [PATCH] Update bst_search.py --- trees/bst_search.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/trees/bst_search.py b/trees/bst_search.py index 2e000b9..648a82c 100644 --- a/trees/bst_search.py +++ b/trees/bst_search.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- # author: bt3gl + def search_bst_recursive(root, val): if root is None or root.val == val: @@ -17,16 +18,15 @@ def search_bst_recursive(root, val): def search_bst_iterative(root, val): - node = root - while node: + while root: - if node.val == val: - return node + if root.val == val: + break - if node.val < val: - node = node.right + if root.val < val: + root = root.right else: - node = node.left + root = root.left - return False + return root