public PathBetweenNodesEnumeration(TreeNode ancestor,
TreeNode descendant) {
super();
if (ancestor == null || descendant == null) {
throw new IllegalArgumentException("argument is null");
}
TreeNode current;
stack = new Stack< TreeNode >();
stack.push(descendant);
current = descendant;
while (current != ancestor) {
current = current.getParent();
if (current == null && descendant != ancestor) {
throw new IllegalArgumentException("node " + ancestor +
" is not an ancestor of " + descendant);
}
stack.push(current);
}
}
|