Tuesday, April 15, 2014

In a Binary Tree, Find Sum of all the nodes

Given a binary tree, find the sum of all the nodes.

int SumOfNodes(Node root)
{
   if(root==NULL)
      return 0;
   return root->data + SumOfNodes(root->left) + SumOfNodes(root->right);
}

No comments:

Post a Comment