Problem while finding/searching a tree node- Urgent help needed!
843805Dec 29 2005 — edited Dec 29 2005Hello,
Can anyone help me with the code below. This code is used to search and return a node whose "nodeName" matches with the nodeName
entered by the user (the 2nd argument).
Although the code finds the node and returns it, the control again comes back to it because of recursion there by ultimately returning a different node.
"aqsWB.treeNode" is a class created by me.
public aqsWB.treeNode findNext(aqsWB.treeNode root, String nodeName) {
aqsWB.treeNode child = null;
for(int i=0; i<root.getChildCount(); i++) {
child = (aqsWB.treeNode)root.getChildAt(i);
if(child.isLeaf()) {
if(child.getNodeName().equalsIgnoreCase(nodeName)) {
break;
}
} else {
if(child.getNodeName().equalsIgnoreCase(nodeName)) {
break;
}
findNext(child, nodeName);
}
}
return child;
}
Thank you.