Solution #1: Here is the recursive code,
int sum(struct node* root) { if(root == NULL) return 0; int lsum = sum(root->left); int rsum = sum(root->right); int temp = root->data; root->data = lsum + rsum; return root->data + temp; }
No comments:
Post a Comment