There is a binary expression tree. The leaves of the expression tree hold operands & nodes contain operator. How will you compute the value stored in the tree ?
int foo(tree* root)
{
if(!root)return 0;
if(!root->left&&!root->right) return root->val;
int left=foo(root->left);
int right=foo(root->right);
return calc(root->val,left,right);
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment