From a712cf06f5cc6632abc309e7f9b45f13c637edb2 Mon Sep 17 00:00:00 2001 From: Amirsoroush Date: Wed, 10 May 2023 09:44:48 +0300 Subject: [PATCH] Chapter06/binary_search_tree - fix the case where node is not found in deletion --- Chapter06/binary_search_tree.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Chapter06/binary_search_tree.py b/Chapter06/binary_search_tree.py index c9ebdbd..5d29aaa 100644 --- a/Chapter06/binary_search_tree.py +++ b/Chapter06/binary_search_tree.py @@ -42,8 +42,8 @@ def get_node_with_parent(self, data): parent = None current = self.root_node if current is None: - return (parent, None) - while True: + return (None, None) + while current is not None: if current.data == data: return (parent, current) elif current.data > data: @@ -51,8 +51,8 @@ def get_node_with_parent(self, data): current = current.left_child else: parent = current - current = current.right_child - return (parent, current) + current = current.right_child + return (None, None) def remove(self, data):