/*
* LRD
*/
typedef struct
{
int tag;
BinTree t;
}Elem;
void nPostOrder(BinTree t)
{
Stack s;
BinTreeNode * p = t;
Elem stnode;
if(t == NULL) return;
s = CreateEmptyStack;
do{
// first push
while(p!=NULL)
{
stnode.tag = 1;
stnode.t = p;
push(s, stnode);
p = leftChild(p);
}
// pop
while(!isEmptyStack(s))
{
stnode = top(s);
pop(s);
p = stnode.t;
}
// second push
if(stnode.tag == 1)
{
stnode.tag = 2;
push(s, stnode);
p = rightChild(p);
break;
}
else visit(root(p));
}while(!isEmptyStack);
}
* LRD
*/
typedef struct
{
int tag;
BinTree t;
}Elem;
void nPostOrder(BinTree t)
{
Stack s;
BinTreeNode * p = t;
Elem stnode;
if(t == NULL) return;
s = CreateEmptyStack;
do{
// first push
while(p!=NULL)
{
stnode.tag = 1;
stnode.t = p;
push(s, stnode);
p = leftChild(p);
}
// pop
while(!isEmptyStack(s))
{
stnode = top(s);
pop(s);
p = stnode.t;
}
// second push
if(stnode.tag == 1)
{
stnode.tag = 2;
push(s, stnode);
p = rightChild(p);
break;
}
else visit(root(p));
}while(!isEmptyStack);
}