主题:大家帮帮我看看哪里出问题了~??
#include "stdio.h"
#include "stdlib.h"
#define MAX 20
#define NULL 0
typedef char TElemType;
typedef int Status;
typedef struct BiTNode{
TELemType data;
struct BiTNode *lchild,*rchild;
}BiTNode, *BiTree;
Status CreateBiTree(BiTree *T){
char ch;
ch=getchar();
if (ch=='#")
(*T)=NULL;
else{
(*T)=(BiTree)malloc(sizeof(BiTree));
(*T)->data=ch;
CreateBiTree(&(*T)->lchild);
CreateBiTree(&(*T)->rchild);
}
return 1;
}
void PreOrder(BiTree T){
if(T){
printf("%2c",T->data);
PreOrder(T->lchild);
PreOrder(T->rchild);
}
}
void LevleOrder(BiTree T) {
BiTree Queue[MAX],b;
int front,rear;
front=rear=0;
if(T)
{Queue[rear++]=T;
while (front!=rear){
b=Queue[front++];
printf("%2c",b->data);
if(p->lchild!=NULL)
Queue[rear++]=p->lchild;
if(p->rchild!=NILL)
Queue[rear++]=p->rchild;
}
}
}//LevelOrder
int depth(BiTree T){
int dep1,dep2;
if(T==NULL) return 0;
else { dep1=depth(T->lchild);
dep2=depth(T->rchild);
return dep1>dep2? dep1+1:dep2+1;
}
}//depth
main(){
BiTree T=NULL;
printf("\nCreate a Binary Tree\n");
CreateBiTree(&T);
printf("\nThe preorder is: \n");
PreOrder(T);
printf("\nThe level order is: \n");
LevleOrder(T);
printf("\nThe depth is:%d\n",depth(T));
}
#include "stdlib.h"
#define MAX 20
#define NULL 0
typedef char TElemType;
typedef int Status;
typedef struct BiTNode{
TELemType data;
struct BiTNode *lchild,*rchild;
}BiTNode, *BiTree;
Status CreateBiTree(BiTree *T){
char ch;
ch=getchar();
if (ch=='#")
(*T)=NULL;
else{
(*T)=(BiTree)malloc(sizeof(BiTree));
(*T)->data=ch;
CreateBiTree(&(*T)->lchild);
CreateBiTree(&(*T)->rchild);
}
return 1;
}
void PreOrder(BiTree T){
if(T){
printf("%2c",T->data);
PreOrder(T->lchild);
PreOrder(T->rchild);
}
}
void LevleOrder(BiTree T) {
BiTree Queue[MAX],b;
int front,rear;
front=rear=0;
if(T)
{Queue[rear++]=T;
while (front!=rear){
b=Queue[front++];
printf("%2c",b->data);
if(p->lchild!=NULL)
Queue[rear++]=p->lchild;
if(p->rchild!=NILL)
Queue[rear++]=p->rchild;
}
}
}//LevelOrder
int depth(BiTree T){
int dep1,dep2;
if(T==NULL) return 0;
else { dep1=depth(T->lchild);
dep2=depth(T->rchild);
return dep1>dep2? dep1+1:dep2+1;
}
}//depth
main(){
BiTree T=NULL;
printf("\nCreate a Binary Tree\n");
CreateBiTree(&T);
printf("\nThe preorder is: \n");
PreOrder(T);
printf("\nThe level order is: \n");
LevleOrder(T);
printf("\nThe depth is:%d\n",depth(T));
}