问题
I can't seem to figure this out
My tree nodes have the following 3 string fields and 3 node fields which are left, middle and right.
This is what I have
public TreeNode findNode(String name) {
TreeNode pointer = this.getRoot();
if (!(name.equals(pointer.getName()))) {
pointer = pointer.getLeft();
findNode(name);
pointer = pointer.getMiddle();
pointer = pointer.getRight();
}
return pointer;
}
I see that the problem is that I keep reseting the pointer to root with every iteration but I think that findNode should only intake string as it's parameter. I don't see a way to do this.
来源:https://stackoverflow.com/questions/29528675/search-a-tree-with-three-nodes