Jun 10, 2009

Create a program that traverses a tree full of nodes and calls a function when it reaches a leaf node.

Create a program that traverses a tree full of nodes and calls a function when it reaches a leaf node.
void callF(Node* root )
{
if(root ==NULL) return;
if(root->left) callF(root->left, fun);
if(root->right)callF(root->right, fun);
if(!root->left && !root->right)
fun();
return;
}

No comments:

Post a Comment