Skip to content

Commit

Permalink
sum of leaf nodes of tree
Browse files Browse the repository at this point in the history
  • Loading branch information
WaderManasi committed Sep 13, 2020
1 parent e483b3e commit 6d84d0a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Tree/Sumofleaf_Tree.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//Given a Binary Tree of size N. The task is to complete the function sumLeaf(), that should return the sum of all the leaf nodes of the given binary tree.

int sumLeaf(Node* root)
{
if(root==NULL) return 0;
int sum=0;
Node* temp=root;
if(temp->right==NULL && temp->left==NULL)
return temp->data;
return sumLeaf(temp->left)+sumLeaf(temp->right);
}

0 comments on commit 6d84d0a

Please sign in to comment.