// in Tree
public int nodeCount()
{
if (root != null)
return root.nodeCount();
else
return 0;
}
// in Node
int nodeCount()
{
int leftCount, rightCount;
if (lChild == null)
leftCount = 0;
else
leftCount = lChild.nodeCount();
if (rChild == null)
rightCount = 0;
else
rightCount = rChild.nodeCount();
return 1 + leftCount + rightCount;
}
|