Skip to content

Instantly share code, notes, and snippets.

@iwilbert
Created July 13, 2014 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iwilbert/5842b8f26cc9482fcca3 to your computer and use it in GitHub Desktop.
Save iwilbert/5842b8f26cc9482fcca3 to your computer and use it in GitHub Desktop.
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