Write a function that prints all the ancestors of a node in a Binary tree. For the tree below, and for 9 the ancestors are 9 2 6.

Difficulty level

This exercise is mostly suitable for students
int print_ancestors(Btree B, Btree e)
{
if(B)
{
if(B == e || print_ancestors(B->left,e)||print_ancestors(B->right,e))
{
printf("%d ",B->data);
return 1;
}
}
return 0;
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
