Write the recursive C function to count the number of nodes present in a binary tree.

Category: Data StructureWrite the recursive C function to count the number of nodes present in a binary tree.
1 Answers
Editor">Editor Staff answered 2 years ago

int count (struct node* t)
{
if(t)
{
int l, r;
l = count(t->left);
r=count(t->right);
return (1+l+r);
}
else
{
return 0;
}
}