mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -04:00
Update bst_search.py
This commit is contained in:
parent
8bc3090801
commit
d50ed323fd
@ -2,6 +2,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# author: bt3gl
|
# author: bt3gl
|
||||||
|
|
||||||
|
|
||||||
def search_bst_recursive(root, val):
|
def search_bst_recursive(root, val):
|
||||||
|
|
||||||
if root is None or root.val == 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):
|
def search_bst_iterative(root, val):
|
||||||
|
|
||||||
node = root
|
while root:
|
||||||
while node:
|
|
||||||
|
|
||||||
if node.val == val:
|
if root.val == val:
|
||||||
return node
|
break
|
||||||
|
|
||||||
if node.val < val:
|
if root.val < val:
|
||||||
node = node.right
|
root = root.right
|
||||||
|
|
||||||
else:
|
else:
|
||||||
node = node.left
|
root = root.left
|
||||||
|
|
||||||
return False
|
return root
|
||||||
|
Loading…
x
Reference in New Issue
Block a user