void printPath(node *p,node *child)
{
  if( p && child)
        std::cout << "Path: " << p->data << " => "  << child->data <<
std::endl;
}

use  this before you assign 'current' to its children.
e.g.

   printPath(p,p->left)
   or
   printPath(p,p->right);


-- 
Amitesh




On Mon, Jun 25, 2012 at 11:34 PM, Nishant Pandey <
[email protected]> wrote:

>
> thiss is iterative inorder  code i am using for printing all the paths of
> the Btree .
>
> but i am not able to manipulate the lengths properly when its perform pop
> up so that i
> can print the paths properly ..
>
> Can any one help by modifying the changes in this code .
>
>
>
> void inorder(struct node *root)
> {
>     stack<struct node*>stack_temp;
>
>     struct node *current,*temp;
>     int path[20];
>     int i =0 ,j=0;
>     if(!root)return ;
>
>     current=root;
>     bool flag=false;
>     //bool ctrl=false;
>     while(!flag)
>     {
>
>         if(current)
>         {
>             //cout<<current->data<<endl;
>             stack_temp.push(current);
>             path[i++]=current->data;
>             if(current->left == NULL && current->right == NULL)
>             {
>                 for(j=0;j<i;j++)
>                     cout<<path[j]<<" ";
>                 //i--;
>
>             }
>
>             cout<<endl;
>             current=current->left;
>
>         }
>         else
>         {
>             if(stack_temp.empty())
>             {
>                 flag=true;
>             }
>             else
>             {
>                 current=stack_temp.top();
>                 stack_temp.pop();
>
>                 i--;
>
>
>                 //if(current->right)
>                 //cout<<current->data<<endl;
>                 current=current->right;
>                 if(current)
>                 i++;
>             }
>
>         }
>
>     }
>
>
> }
>
>
>
> --
> Cheers,
>
> Nishant Pandey |Specialist Tools Development  |  
> [email protected]<[email protected]> |
> +91-9911258345
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to