forked from WaderManasi/Knowing-DataStructures-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e483b3e
commit 6d84d0a
Showing
1 changed file
with
11 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |