#include<stdio.h>
struct node
{int data;
struct node *lch;
struct node *rch;};
typedef struct node bitree;
bitree *creat()
{bitree *t;
int x;
scanf("%d",&x);
if(x==0) t=NULL;
else
{t=(bitree*)malloc(sizeof(bitree));
t->data=x;
t->lch=creat();
t->rch=creat();}
return t;}
void preorder(bitree * b)
{bitree *p;
bitree *stack[10];
int top=-1;
if (b!=NULL)
{top=top+1;
stack[top]=b;
while(top>-1)
{p=stack[top];
top=top-1;
printf("%d",p->data);
if(p->rch!=NULL)
{top=top+1;
stack[top]=p->rch;}
if(p->lch!=NULL)
{top=top+1;
stack[top]=p->lch;}
}
printf("\n");}
}
main()
{bitree *b;
b=creat();
preorder(b);
getch();
}
追é®æé误
追çæè¿æ¾ç¤ºæ²¡æå