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  |
npan...@google.com<gvib...@google.com> |
+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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to