typedef struct Bitnode{
int data;
struct Bitnode *lchild,*rchild;
}BTree;
BTree *Ini_BTree(){
BTree *bt;
int a;
bt=(BTree*)malloc(sizeof(BTree));
printf("输入根节点:(0表示空树)\n");
scanf("%d",&a);
if(a==0){
printf("这是空树!");
exit(0);
}
bt->data=a;
bt->lchild=NULL;
bt->rchild=NULL;
return bt;
}
creat_BiTree(BTree *bt){
int a;
BTree *Node;
printf("请输入%d节点的左孩子(0为空)\n",bt->data);
scanf("%d",&a);
if(a!=0){
Node=(BTree*)malloc(sizeof(BTree));
Node->data=a;
Node->lchild=NULL;
Node->rchild=NULL;
bt->lchild=Node;
creat_BiTree(bt->lchild);
}
printf("请输入%d节点的右孩子(0为空)\n",bt->data);
scanf("%d",&a);
if(a!=0){
Node=(BTree*)malloc(sizeof(BTree));
Node->data=a;
Node->lchild=NULL;
Node->rchild=NULL;
bt->rchild=Node;
creat_BiTree(bt->lchild);
}
return 0;
}
void PerorderTraverse(BTree* bt){
if(bt!=NULL){
printf("%d-->",bt->data);
PerorderTraverse(bt->lchild);
PerorderTraverse(bt->rchild);
}
}
void InorderTraverse(BTree* bt){
if(bt!=NULL){
InorderTraverse(bt->lchild);
printf("%d-->",bt->data);
InorderTraverse(bt->rchild);
}
}
void PostOrderTraverse(BTree* bt){
if(bt!=NULL){
PostOrderTraverse(bt->lchild);
PostOrderTraverse(bt->rchild);
printf("%d-->",bt->data);
}
}
int data;
struct Bitnode *lchild,*rchild;
}BTree;
BTree *Ini_BTree(){
BTree *bt;
int a;
bt=(BTree*)malloc(sizeof(BTree));
printf("输入根节点:(0表示空树)\n");
scanf("%d",&a);
if(a==0){
printf("这是空树!");
exit(0);
}
bt->data=a;
bt->lchild=NULL;
bt->rchild=NULL;
return bt;
}
creat_BiTree(BTree *bt){
int a;
BTree *Node;
printf("请输入%d节点的左孩子(0为空)\n",bt->data);
scanf("%d",&a);
if(a!=0){
Node=(BTree*)malloc(sizeof(BTree));
Node->data=a;
Node->lchild=NULL;
Node->rchild=NULL;
bt->lchild=Node;
creat_BiTree(bt->lchild);
}
printf("请输入%d节点的右孩子(0为空)\n",bt->data);
scanf("%d",&a);
if(a!=0){
Node=(BTree*)malloc(sizeof(BTree));
Node->data=a;
Node->lchild=NULL;
Node->rchild=NULL;
bt->rchild=Node;
creat_BiTree(bt->lchild);
}
return 0;
}
void PerorderTraverse(BTree* bt){
if(bt!=NULL){
printf("%d-->",bt->data);
PerorderTraverse(bt->lchild);
PerorderTraverse(bt->rchild);
}
}
void InorderTraverse(BTree* bt){
if(bt!=NULL){
InorderTraverse(bt->lchild);
printf("%d-->",bt->data);
InorderTraverse(bt->rchild);
}
}
void PostOrderTraverse(BTree* bt){
if(bt!=NULL){
PostOrderTraverse(bt->lchild);
PostOrderTraverse(bt->rchild);
printf("%d-->",bt->data);
}
}