Link to home
Start Free TrialLog in
Avatar of axtur
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;
    }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of lbertacco
lbertacco

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of axtur
axtur

ASKER

perfect solution