方法二:
#include<stdio.h>
#include<stdlib.h>
typedef struct node{
int data;
struct node * lchild;
struct node * rchild;
}BTree;
void create(BTree **tree){
int temp;
scanf("%d",&temp);
if(temp==0){
*tree=NULL;
return;
}else{
*tree=(BTree*)malloc(sizeof(BTree));
if(*tree==NULL)
return;
(*tree)->data=temp;
create(&((*tree)->lchild));
create(&((*tree)->rchild));
}
}
void pprint(BTree *tree){
if(tree){
printf("%d ",tree->data);
pprint(tree->lchild);
pprint(tree->rchild);
}
}
void main()
{
BTree *head=(BTree*)malloc(sizeof(BTree));
create(&head);
pprint(head);
}