遍历二叉树的问题
来源:百度知道 编辑:UC知道 时间:2024/05/21 12:27:43
#include<stdio.h>
#include<stdlib.h>
typedef struct BiTNode{
int data;
struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
BiTree CreateBiTree(){
int n;
BiTree T;
printf("input the value of the node\n");
scanf("%d",&n);
if(n==0) T=NULL;
else{
T=(BiTree)malloc(sizeof(BiTNode));
if(!T)
printf("alloc error!\n");
T->data=n;
CreateBiTree(T->lchild);
CreateBiTree(T->rchild);
}
return T;
}
int ShowTree(BiTree T){
if(T){
printf("%d\t",T->data);
if(ShowTree(T->lchild))
if(ShowTree(T->rchild)) return 1;
return 0;
}
else return 1;
}
void main(){
BiTree TreeHead;
TreeHead=Cre
#include<stdlib.h>
typedef struct BiTNode{
int data;
struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
BiTree CreateBiTree(){
int n;
BiTree T;
printf("input the value of the node\n");
scanf("%d",&n);
if(n==0) T=NULL;
else{
T=(BiTree)malloc(sizeof(BiTNode));
if(!T)
printf("alloc error!\n");
T->data=n;
CreateBiTree(T->lchild);
CreateBiTree(T->rchild);
}
return T;
}
int ShowTree(BiTree T){
if(T){
printf("%d\t",T->data);
if(ShowTree(T->lchild))
if(ShowTree(T->rchild)) return 1;
return 0;
}
else return 1;
}
void main(){
BiTree TreeHead;
TreeHead=Cre
#include<stdio.h>
#include<stdlib.h>
typedef struct BiTNode{
int data;
struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
BiTree CreateBiTree(){
int n;
BiTree T;
printf("input the value of the node\n");
scanf("%d",&n);
if(n==0) T=NULL;
else{
T=(BiTree)malloc(sizeof(BiTNode));
if(!T)
printf("alloc error!\n");
T->data=n;
// 这里改一下
T->lchild=CreateBiTree();
T->rchild=CreateBiTree();
}
return T;
}
int ShowTree(BiTree T){
if(T){
printf("%d\t",T->data);
if(ShowTree(T->lchild))
if(ShowTree(T->rchild)) return 1;
return 0;
}
else return 1;
}
void main(){
BiTree TreeHead;
TreeHead=CreateBiTr