Last active
September 24, 2018 16:22
-
-
Save senvey/6da92843175095a1e974 to your computer and use it in GitHub Desktop.
Inorder successor in a binary tree
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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