#include <stdio.h>
#include <stdlib.h>
#define ElemType char
typedef struct {
BiTree *base;
BiTree *top;
}stack;
//节点声明,数据域、左孩子指针、右孩子指针
typedef struct BiTNode{
char data;
struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
void jianli(stack *s)
{
s->top=(BiTree*)malloc(sizeof(BiTree)*100);
s->base=s->top;
}
//先序建立二叉树
BiTree CreateBiTree(){
char ch;
BiTree T;
scanf("%c",&ch);
if(ch=='#')T=0;
else{
T = (BiTNode *)malloc(sizeof(BiTNode));
T->data = ch;
T->lchild = CreateBiTree();
T->rchild = CreateBiTree();
}
return T;//返回根节点
}
void push(stack *s,BiTree T)
{
*s->top++=T;
}
BiTree pop(stack *s){
BiTree U;
s->top--;
U=*s->top;
return U;
}
void feidigui(BiTree T)
{
stack s;
jianli(&s);
if (T){
while (T)
{printf("%c",T->data);
if (T->lchild) {push(s,T);
T=T->lchild;}
else if (T->rchild) T=T->rchild;
else if ((s->top)-(s->base)) T=pop(s);
else T=0;
}
}}
void main(){
BiTree T;
T = CreateBiTree();//建立
feidigui(T);
}
编译不过。。