Fix error in avl_tree del_node function (#11510)

* fixed error in del_node function

* Update avl_tree.py

---------

Co-authored-by: Maxim Smolskiy <mithridatus@mail.ru>
This commit is contained in:
Rachel Spears 2025-01-23 21:59:36 -08:00 committed by GitHub
parent c666db3729
commit 13e4d3e76c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -221,6 +221,10 @@ def del_node(root: MyNode, data: Any) -> MyNode | None:
else: else:
root.set_right(del_node(right_child, data)) root.set_right(del_node(right_child, data))
# Re-fetch left_child and right_child references
left_child = root.get_left()
right_child = root.get_right()
if get_height(right_child) - get_height(left_child) == 2: if get_height(right_child) - get_height(left_child) == 2:
assert right_child is not None assert right_child is not None
if get_height(right_child.get_right()) > get_height(right_child.get_left()): if get_height(right_child.get_right()) > get_height(right_child.get_left()):