#include<stdio.h>
#include<malloc.h>
typedef struct bintree
{
int data;
struct bintree *lchild,*rchild;
}BTN,*BTP;
//按先序创建一个二叉树
BTP creatbt()
{
BTP bt;int n;
scanf("%d",&n);
if(n)
{
bt=(BTP)malloc(sizeof(BTN));
bt->data=n;
bt->lchild=creatbt();
bt->rchild=creatbt();
}
else
bt=NULL;
return bt;
}
//先序遍历
void preorder(BTP bt)
{
if(bt)
{
printf("%4d",bt->data);
preorder(bt->lchild);
preorder(bt->rchild);
}
}
void main()
{
BTP bt;
bt=creatbt();
preorder(bt);
}