I built a tree consisting of nodes with each node having an attribute and a list of successors. I am trying to implement a recursive function that starts to move through the tree for a given node (in this example, in the node "Method"). The function should count the number of nested nodes with the given attribute. In the end, I want to return the largest number found in one branch. Speaking about this example, I would like to find the maximum number of nested nodes with the attribute "Loop", which will be equal to 3 (the corresponding branch is marked in orange).
Example:
Currently, my approach is as follows:
private static int getLNDforMethod(DirectedNodeInterface curNode, int currentLND) {
NodeIterator successors = curNode.getSuccessors();
while(successors.hasNext())
{
successors.next();
DirectedNodeInterface curSuc = (DirectedNodeInterface) successors.getNode();
if(isLoop(curSuc))
{
++currentLND;
}
currentLND = getLNDforMethod(curSuc, currentLND);
}
return currentLND;
}
, , . , 3 ( , ), 7 , "" .
-, . - ?