Write a recursive function that returns the sum of all the nodes in a binary tree of integers.
Difficulty level
This exercise is mostly suitable for students
int sum_rec(Btree B)
{
if (B == NULL)
return 0;
return B->data+sum_rec(B->left) + sum_rec(B->right);
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Lagrange form of the polynomial interpolation