From 9f5f4ffcd50cce6ec557402a525854ffadb7ffc5 Mon Sep 17 00:00:00 2001 From: Isidro Arias Date: Wed, 26 Apr 2023 12:56:36 +0200 Subject: [PATCH] is right test --- data_structures/binary_tree/binary_search_tree.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/data_structures/binary_tree/binary_search_tree.py b/data_structures/binary_tree/binary_search_tree.py index 6ed9af447..2babb4829 100644 --- a/data_structures/binary_tree/binary_search_tree.py +++ b/data_structures/binary_tree/binary_search_tree.py @@ -38,6 +38,11 @@ True >>> t.search(-1) is not None False +>>> t.search(6).is_right +True +>>> t.search(1).is_right +False + >>> t.get_max().value 14 >>> t.get_min().value @@ -177,12 +182,12 @@ class BinarySearchTree: elif node.right is None: # Has only left children self.__reassign_nodes(node, node.left) else: - tmp_node = self.get_max( + predecessor = self.get_max( node.left ) # Gets the max value of the left branch - self.remove(tmp_node.value) # type: ignore + self.remove(predecessor.value) # type: ignore node.value = ( - tmp_node.value # type: ignore + predecessor.value # type: ignore ) # Assigns the value to the node to delete and keep tree structure def preorder_traverse(self, node: Node | None) -> Iterable: