c语言 二叉树 改错

来源:百度知道 编辑:UC知道 时间:2024/07/06 19:55:09
生成 及三种遍历
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#define NULL 0

typedef struct BiTNode{
char data;
struct BiNode *lchild,*rchild;
}BiTNode,*BiTree;

Create(BiTree T){
char ch;
ch=getchar();
if(ch=='0')
T=NULL;
else
{
if(!(T=(BiTNode*)malloc(sizeof(BiTNode))))
printf("error");
T->data=ch;
T->lchild=Create(T->lchild);
T->rchild=Create(T->rchild);
}
return T;
}
Prevorder(BiTree T){
printf("%c",T->data);
Preorder(T->lchild);
Preorder(T->rchild);
}
Inorder(BiTree T){
Inorder(T->lchild);
printf("%c",T->data);
Inorder(T->rchild);
}
Postorder(BiTree T){
Postorder(T->lchild);
Postorder(T->rchild);
printf("%c",T->data);<

typedef struct BiTNode{
char data;
struct BiNode *lchild,*rchild; //改成struct BiTNode *lchild,*rchild
}BiTNode,*BiTree;

Create(BiTree T){ //改成 BiTree Create(BiTree T){
char ch;
ch=getchar();
if(ch=='0')
T=NULL;
else
{
if(!(T=(BiTNode*)malloc(sizeof(BiTNode))))
printf("error");
T->data=ch;
T->lchild=Create(T->lchild);
T->rchild=Create(T->rchild);
}
return T;
}

Prevorder(BiTree T){
printf("%c",T->data);
Preorder(T->lchild);
Preorder(T->rchild);
} //Preorder 是Prevorder吧

main函数中Previsit(T); Previsit没定义就拿来用?

//---------------------------------------------------------------------------
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#define NULL 0

typedef struct BiTNode{
char data;