Hello to every body
I hope every one keep in best state.
I want to help me in solve this problem in my Sheet
IN TREE structuring
If I use pointer to root of tree, it make run time error .
I need to this pointer in 4 function
int countNodes( TreeNode * root )
{
if ( root == NULL )
return 0;
else {
int count = 1;
count += countNodes(root->left);
count += countNodes(root->right);
return count;
}
} // end countNodes()
// in main
cout <<countNodes (ObjectTree.ReturnRoot() );
// in Tree class
TreeNode* ReturnRoot ()
{
return root ;
}
the rest functom is tha same this :
void preorder( TreeNode *root )
{
if ( root != NULL ) { // (Otherwise, there's nothing to print.)
cout << root->item << " ";
preorder( root->left );
preorder( root->right ); }
}
.
.
.
I think that I need to make the function is a global function not a member function because I think the efficiency solution to this problem is recursive
I hooope to help me