From 9218a96cc74f59cef13457597b72c70011421a9c Mon Sep 17 00:00:00 2001 From: Shaurya Bisht <87357655+ShauryaDusht@users.noreply.github.com> Date: Sun, 13 Oct 2024 12:22:40 +0000 Subject: [PATCH] improved del_node func(13) --- data_structures/binary_tree/avl_tree.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/data_structures/binary_tree/avl_tree.py b/data_structures/binary_tree/avl_tree.py index 6056863df..97236ac4d 100644 --- a/data_structures/binary_tree/avl_tree.py +++ b/data_structures/binary_tree/avl_tree.py @@ -227,8 +227,8 @@ def del_node(root: MyNode | None, data: Any) -> MyNode | None: right_child = root.get_right() assert right_child is not None temp = get_min_value_node(right_child) - - root.set_data(temp.get_data()) + if temp is not None: + root.set_data(temp.get_data()) root.set_right(del_node(root.get_right(), temp.get_data())) root.set_height( @@ -370,4 +370,4 @@ if __name__ == "__main__": random.shuffle(lst) for i in lst: t.del_node(i) - print(str(t)) + print(str(t)) \ No newline at end of file