Created
July 13, 2014 23:22
-
-
Save iwilbert/5842b8f26cc9482fcca3 to your computer and use it in GitHub Desktop.
This file contains 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
public TreeNode getNext(TreeNode node) { | |
if (node.right != null) | |
return getMin(node.right); | |
TreeNode parent = node.parent; | |
while (parent != null && parent.right == node) { | |
node = parent; | |
parent = node.parent; | |
} | |
return parent; | |
} | |
private TreeNode getMin(TreeNode node) { | |
while (node.left != null) | |
node = node.left; | |
return node; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment