I tried to print the all ancester of the given node but getting few error please tell me i stored all ancester in a stack and thn returned stack
@kailash_01 hey instead of using this condition:
if(printallancester(root->left,key)==s||printallancester(root->right,key)==s)
{
s.push(root->data);
return s;
}
use this condition as you have to check ki woh node us root ke left subtree me exist krti hai ya nhi:
if
( printAncestors(root->left, target) ||
printAncestors(root->right, target) )
{
cout << root->data <<
" "
;
return
true
;
}
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.