From dd97ffb201bc630cf02b85935f0f64fc67c52451 Mon Sep 17 00:00:00 2001 From: Raphael Roberts Date: Wed, 13 Nov 2019 17:50:05 -0600 Subject: [PATCH] Added lookup to BST --- BST.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/BST.py b/BST.py index 7dbdff4..fc32d5b 100644 --- a/BST.py +++ b/BST.py @@ -55,6 +55,15 @@ class BST: parent.left = to_add self.size += 1 + def lookup(self, value): + current = self.root + while current.value != value and current is not None: + if value < current.value: + current = current.left + elif value > current.value: + current = current.right + return current + def in_order(self): ret = [] in_order_rec(self.root, ret)