diff --git a/forest/binary_trees/single_threaded_binary_trees.py b/forest/binary_trees/single_threaded_binary_trees.py index c2f14b2..7dcf1ef 100644 --- a/forest/binary_trees/single_threaded_binary_trees.py +++ b/forest/binary_trees/single_threaded_binary_trees.py @@ -582,17 +582,12 @@ def delete(self, key: Any) -> None: elif deleting_node.right and deleting_node.left: replacing_node: Node = self.get_leftmost(node=deleting_node.right) successor = self.get_successor(node=replacing_node) - # the minmum node is not the direct child of the deleting node + # the leftmost node is not the direct child of the deleting node if replacing_node.parent != deleting_node: - if replacing_node.is_thread: - self._transplant( - deleting_node=replacing_node, replacing_node=None - ) - else: - self._transplant( - deleting_node=replacing_node, - replacing_node=replacing_node.right, - ) + self._transplant( + deleting_node=replacing_node, + replacing_node=replacing_node.right, + ) replacing_node.right = deleting_node.right replacing_node.right.parent = replacing_node diff --git a/setup.py b/setup.py index cbf287e..25487e6 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ # This call to setup() does all the work setuptools.setup( name="forest-python", - version="0.5.2", + version="0.5.3", description="The Forest Project in Python", long_description=README, long_description_content_type="text/x-rst", diff --git a/tests/test_single_threaded_binary_trees.py b/tests/test_single_threaded_binary_trees.py index 9d0be14..211c919 100644 --- a/tests/test_single_threaded_binary_trees.py +++ b/tests/test_single_threaded_binary_trees.py @@ -256,3 +256,34 @@ def test_deletion_left_threaded_case(basic_tree): (4, "4"), (1, "1"), ] == [item for item in tree.reverse_inorder_traverse()] + + +def test_deletion_left_threaded_case_2(): + """Test the deletion of a left threaded binary tree.""" + tree = single_threaded_binary_trees.LeftThreadedBinaryTree() + + test_tree = [ + (4, "4"), + (1, "1"), + (7, "7"), + (3, "3"), + (5, "5"), + (8, "8"), + (2, "2"), + (6, "6"), + ] + + for key, data in test_tree: + tree.insert(key=key, data=data) + + tree.delete(4) + + assert [ + (8, "8"), + (7, "7"), + (6, "6"), + (5, "5"), + (3, "3"), + (2, "2"), + (1, "1"), + ] == [item for item in tree.reverse_inorder_traverse()]