Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9218a96

Browse files
committedOct 13, 2024·
improved del_node func(13)
1 parent 4fc0c00 commit 9218a96

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed
 

‎data_structures/binary_tree/avl_tree.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ def del_node(root: MyNode | None, data: Any) -> MyNode | None:
227227
right_child = root.get_right()
228228
assert right_child is not None
229229
temp = get_min_value_node(right_child)
230-
231-
root.set_data(temp.get_data())
230+
if temp is not None:
231+
root.set_data(temp.get_data())
232232
root.set_right(del_node(root.get_right(), temp.get_data()))
233233

234234
root.set_height(
@@ -370,4 +370,4 @@ def _test() -> None:
370370
random.shuffle(lst)
371371
for i in lst:
372372
t.del_node(i)
373-
print(str(t))
373+
print(str(t))

0 commit comments

Comments
 (0)
Please sign in to comment.