Skip to content

Instantly share code, notes, and snippets.

@senvey
Last active September 24, 2018 16:22
Show Gist options
  • Save senvey/6da92843175095a1e974 to your computer and use it in GitHub Desktop.
Save senvey/6da92843175095a1e974 to your computer and use it in GitHub Desktop.
Inorder successor in a binary tree
def successor(node):
if node.right:
c = node.right
while c.left:
c = c.left
return c
n, p = node, node.parent
# note: check if p is not None
while p and n != p.left:
n, p = p, p.parent
return p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment