Search a tree with three nodes?

岁酱吖の 提交于 2019-12-25 03:15:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!