#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node* left;
struct node* right;
};
struct node* create()
{
int num;
struct node *p;
scanf("%d",&num);
if(num==0)
p=NULL;
else
{
p=(struct node*)malloc(sizeof(struct node));
if(p==NULL)
exit(0);
p->data=num;
p->left=NULL;
p->right=NULL;
p->left=create();
p->right=create();
}
return p;
}
void output(struct node *bt)
{
if(bt!=NULL)
{
printf("%d\n",bt->data);
output(bt->left);
output(bt->right);
}
}
int main()
{
struct node *bt=(struct node*)malloc(sizeof(struct node));
bt=create();
printf("qianxu##############\n");
output(bt);
return 0;
#include<stdlib.h>
struct node
{
int data;
struct node* left;
struct node* right;
};
struct node* create()
{
int num;
struct node *p;
scanf("%d",&num);
if(num==0)
p=NULL;
else
{
p=(struct node*)malloc(sizeof(struct node));
if(p==NULL)
exit(0);
p->data=num;
p->left=NULL;
p->right=NULL;
p->left=create();
p->right=create();
}
return p;
}
void output(struct node *bt)
{
if(bt!=NULL)
{
printf("%d\n",bt->data);
output(bt->left);
output(bt->right);
}
}
int main()
{
struct node *bt=(struct node*)malloc(sizeof(struct node));
bt=create();
printf("qianxu##############\n");
output(bt);
return 0;
}
输入:1 2 3 0 0 4 5 0 0 0 6 0 7 8 0 0 9 0 0
输出:1 2 3 4 5 6 7 8 9