Ok so i have this function countnodes that calculates height and number of nodes in tree. I just don't understand how i can implement the function so it derives both height and nodes in same function.
1 2 3 4 5
template <typename NodeType>
int CBSTree<NodeType>::CountNodes(const CTreeNode<NodeType> *nodePtr, int currDepth, int &numNodes )const
{
} // end of "CBSTree::CountNodes"
if ( nodePtr == NULL )
return 0; // The tree is empty. It contains no nodes.
else
{
NodeType count = 1; // Start by counting the root.
count += CountNodes(nodePtr->m_left,currDepth,numNodes); // Add the number of nodes
// in the left subtree.
count += CountNodes(nodePtr->m_right,currDepth,numNodes); // Add the number of nodes
// in the right subtree.
return count; // Return the total.
}
Then i have this function that suppose to call countnode function