#include<stdio.h>
using namespace std;
#include<iostream>
struct node{
       char data;
       struct node *left;
       struct node *right;
       int flag;
       };
struct stack{
       struct node *dd[50];
       int top;
       };
void push(struct stack *, struct node *);
struct node * pop(struct stack *);
void postorder(struct node *);
int main(){
    struct node *t;
    t=(node *)malloc(sizeof(struct node));
    t->data='a';
    t->left=t->right=NULL;
    t->flag=0;
    struct node *p;
    p=(node *)malloc(sizeof(struct node));
    p->data='b';
    p->left=p->right=NULL;
    p->flag=0;
    t->left=p;
    struct node *q;
    q=(node *)malloc(sizeof(struct node));
    q->data='c';
    q->left=q->right=NULL;
    q->flag=0;
    t->right=q;
    struct node *r;
    r=(node *)malloc(sizeof(struct node));
    r->data='d';
    r->left=r->right=NULL;
    r->flag=0;
    p->left=r;
    struct node *s;
    s=(node *)malloc(sizeof(struct node));
    s->data='e';
    s->left=s->right=NULL;
    s->flag=0;
    p->right=s;
    postorder(t);


    system("pause");
    return 0;
}
void postorder(struct node *t){
            struct stack g;
            struct node *temp1,*temp2;
            g.top=-1;
            while(t!=NULL){
                           push(&g,t);
                           t=t->left;

            }
            while(g.top!=-1){
                             t=pop(&g);
                             if(t->flag==0){
                                            t->flag=1;
                                            push(&g,t);
                                            t=t->right;
                                            while(t!=NULL){
                                                           push(&g,t);
                                                           t=t->left;
                                            }
                             }
                             else {
                                  cout<<t->data;
                             }


                             }

}








void push(struct stack *g, struct node *n){
     if(g->top<50){
                   g->dd[g->top+1]=n;
                   g->top++;
     }
     else cout<<"stack full"<<"\n";
     }
struct node * pop(struct stack *g){
       struct node *temp;
       if(g->top==-1){

                      cout<<"stack already empty"<<"\n";
                      return 0;
       }
       else {
            temp=g->dd[g->top];
            g->top--;
            return temp;
       }
       }



















On Wed, Jun 30, 2010 at 8:49 PM, UMESH KUMAR <kumar.umesh...@gmail.com>wrote:

> Hello everybody,
>
> Write a Code in C/C++  *Iterative * for Traversing BST (Binary Tree)
> *POSTORDER *,this is my Problem.
>
>
>
>
>
>
>
> Thanks and regards
> Umesh Kumar from
>  D.U.
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
With Regards,
Jalaj Jaiswal
+919026283397
B.TECH IT
IIIT ALLAHABAD

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@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