Skip to content

Commit 2d2c6d9

Browse files
committed
fixed error in del_node function
1 parent ed1900f commit 2d2c6d9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

data_structures/binary_tree/avl_tree.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,15 @@ def del_node(root: MyNode, data: Any) -> MyNode | None:
215215
return root
216216
else:
217217
root.set_left(del_node(left_child, data))
218-
# root.get_data() < data
219218
elif right_child is None:
220219
return root
221220
else:
222221
root.set_right(del_node(right_child, data))
223222

223+
# Re-fetch left_child and right_child references
224+
left_child = root.get_left()
225+
right_child = root.get_right()
226+
224227
if get_height(right_child) - get_height(left_child) == 2:
225228
assert right_child is not None
226229
if get_height(right_child.get_right()) > get_height(right_child.get_left()):

0 commit comments

Comments
 (0)