Question:

Given a binary tree and a node, print all the ancestors of that node.

1
/ \
4 5
/ \ / \
2 3 7 8

print all the ancestors of 7 ans:1 5 7


Solution: boolean findAncestor(node root, node n){
if(root == null)
return false;
if(root->left == n || root->right == n || findAncestor(root->left,n) ||
findAncestor(root->right,n))
{
print(root);
return true;
}

return false;
}