void Preorder(Node *root)
{
Node *p;
Stack *top = NULL;
top = Push(top, root);
printf("%d ", top->ds->info);
p = root->lchild;
while (1){
for (; p; p = p->lchild){
printf("%d ", p->info);
top = Push(top, p);
}
do
if (top){
p = GetTop(top);
p = p->rchild;
top = Pop(top);
} else
return;
while (!p);
}
}
void Inorder(Node *root)
{
Node *p;
Stack *top = NULL;
top = Push(top, root);
p = root->lchild;
while (1){
for (; p; p = p->lchild)
top = Push(top, p);
do
if (top){
p = GetTop(top);
printf("%d ", p->info);
p = p->rchild;
top = Pop(top);
} else
return;
while (!p);
}
}
void Postorder(Node *root)
{
int Continue;
Node *p, *flag;
Stack *top = NULL;
top = Push(top, root);
p = root->lchild;
while (1){
for (; p; p = p->lchild)
top = Push(top, p);
Continue = 1;
flag = NULL;
do
if (top){
p = GetTop(top);
if (p->rchild != flag){
p = p->rchild;
Continue = 0;
} else{
printf("%d ", p->info);
flag = p;
top = Pop(top);
}
} else
return;
while (Continue);
}
}