Created
July 6, 2015 18:41
-
-
Save ttfkam/5229aa2b71aee1df0c03 to your computer and use it in GitHub Desktop.
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
using namespace std; | |
struct Node { | |
int value; | |
node* left; | |
node* right; | |
} | |
boolean findSum(Node* ref, int prev, int target) { | |
if (!ref) { | |
return false; | |
} | |
int sum = ref->value + prev; | |
if (sum == target || findSum(ref->left, sum, target) || findSum(ref->right, sum, target)) { | |
cout << ref.value; | |
return true; | |
} | |
return false; | |
} | |
int target = 5; | |
if (!findSum(head, 0, target)) { | |
cerr << "Value << target << " is not in the tree" << endl; | |
} | |
/* | |
3: 1,4,9 ; 1,7,12 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment