#include<stdio.h>
#include<stdlib.h>
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define MAXSIZE 100
typedef int Status;
typedef char ElemType;
typedef struct Node
{
char data;
struct Node* lchild, * rchild;
}*BiTree, BiNode;
typedef struct SNode
{
BiTree top;
BiTree base;
int capacity;
}*Stack, SNode;
Status Great(BiTree* T)
{
char e;
scanf("%c", &e);
if (e == '#')
(*T) = NULL;
else
{
(*T) = (BiNode*)malloc(sizeof(BiNode));
if (!(*T)) exit(0);
(*T)->data = e;
Great(&(*T)->lchild);
Great(&(*T)->rchild);
}
return OK;
}
Status Greats(Stack S)
{
S->base = (BiTree)malloc(MAXSIZE * sizeof(BiNode));
if (!S->base) exit(0);
S->top = S->base;
S->capacity = MAXSIZE;
return OK;
}
Status Push(Stack S, BiTree e)
{
S->top = e;
S->top++;
return OK;
}
Status Pop(Stack S, BiTree e)
{
e = --S->top;
return OK;
}
Status isEmpty(Stack S)
{
if (S->top == S->base)
{
return 1;
}
else return 0;
}
Status Midtraverst(BiTree T)
{
SNode S;
Greats(&S);
BiTree p;
p = T;
while (p || !isEmpty(&S))
{
BiTree q;
if (p)
{
Push(&S, p);
p = p->lchild;
}
else
{
char e;
Pop(&S, q);
printf("%d", q->data);
p = q->rchild;
}
return OK;
}
}
int main()
{
BiTree T;
Great(&T);
Midtraverst(T);
return 0;
}