mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-06-19 04:19:26 -04:00
Update bst_delete_node.py
This commit is contained in:
parent
122a535241
commit
a3ce5db3a5
1 changed files with 8 additions and 8 deletions
|
@ -21,14 +21,14 @@ def predecessor(root):
|
|||
|
||||
def delete_node(root, key):
|
||||
|
||||
if not root:
|
||||
if root is None:
|
||||
return root
|
||||
|
||||
if key > root.val:
|
||||
root.right = deleteNode(root.right, key)
|
||||
root.right = delete_node(root.right, key)
|
||||
|
||||
elif key < root.val:
|
||||
root.left = deleteNode(root.left, key)
|
||||
root.left = delete_node(root.left, key)
|
||||
|
||||
else:
|
||||
if not (root.left or root.right):
|
||||
|
@ -36,11 +36,11 @@ def delete_node(root, key):
|
|||
|
||||
elif root.right:
|
||||
root.val = successor(root)
|
||||
root.right = deleteNode(root.right, root.val)
|
||||
root.right = delete_node(root.right, root.val)
|
||||
|
||||
else:
|
||||
root.val = predecessor(root)
|
||||
root.left = deleteNode(root.left, root.val)
|
||||
root.left = delete_node(root.left, root.val)
|
||||
|
||||
return root
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue