我有一個findNode方法,它在treenode中查找目標字符串。我遇到的問題是,我的遞歸方法似乎只是沿着樹的一個分支而沒有像我認爲應該覆蓋的洞樹。如果您需要更多代碼,請詢問。遞歸方法沒有翻譯所有的樹節點
public GeneralTreeNode findNode(String targetName) {
// name is the current name of the node
if(targetName.equals(this.name)) return this;
// children is a HashSet of all the nodes children
for(GeneralTreeNode child : children) return child.findNode(targetName);
// no node containing the string could be found
return null;
}
感謝您的回覆! – 2014-09-25 08:20:22