axtur
asked on
Recursive Get Tree Size
I need a small recursive method able to return a given multigrade tree size (the number of items contained in it), every node has several children. This other method returns the tree height, I place it as an example so you can figure out the structure of the tree.
public int getHeight(int height, Element element, int maxHeight){
if(height > maxHeight)
maxHeight = height;
int i=0;
for(i = 0; i < element.getNumChildren(); i++)
return getHeight(height+1,element.getChild(i),maxHeight);
return maxHeight;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER