Skip to content

Instantly share code, notes, and snippets.

@lichenbo
Created July 14, 2013 14:48
Show Gist options
  • Save lichenbo/5994510 to your computer and use it in GitHub Desktop.
Save lichenbo/5994510 to your computer and use it in GitHub Desktop.
static <K,V> TreeMap.Entry<K,V> successor(Entry<K,V> t) {
if (t == null)
return null;
else if (t.right != null) {
Entry<K,V> p = t.right;
while (p.left != null)
p = p.left;
return p;
} else {
Entry<K,V> p = t.parent;
Entry<K,V> ch = t;
while (p != null && ch == p.right) {
ch = p;
p = p.parent;
}
return p;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment