Ah, yes - I see what you mean
A real leaf has both left and right NULL pointers
Your logic is looking better at the moment then - what results are you getting?
Printable View
Ah, yes - I see what you mean
A real leaf has both left and right NULL pointers
Your logic is looking better at the moment then - what results are you getting?
I hope i get it right this time:
Code:void BST::shortestPath(node *rt,stack &s,int minHt)
{
if(rt == NULL)
return;
stack.push(rt); // store node during pre-traversal
// check for whether min ht is reached and the last node is a leaf
if( (minHt==0) && (rt->left == NULL) && (rt->right == NULL) )
{s.print(); // print the value of the nodes
s.pop();
return;}
shortestPath(rt->left,s, minHt-1);
shortestPath(rt->right,s, minHt-1);
s.pop(); // remove node during post-treversal
}