注册 登录
编程论坛 数据结构与算法

二叉树的代码,求修改错误

无妄 发布于 2014-04-29 15:08, 514 次点击
#include
#include
typedef struct Node
{
    char data;
    struct Node*LChild;
    struct Node*RChild;
}BiTNode,*BiTree;
void CreateBiTree(BiTree *bt)
{
    char ch;
    ch=getchar( );
    if(ch=='.')*bt=NULL;
    else
    {
        *bt=(BiTree)malloc(sizeof(Node));
        (*bt)->data=ch;
        CreateBiTree(&((*bt)->LChild));
        CreateBiTree(&((*bt)->RChild));
    }
}
void PreOrder(BiTree root)
{
    if(root!=NULL)
    {
        printf("%c",root->data);
        PreOrder(root->LChild);
        PreOrder(root->RChild);
    }
}
void InOrder(BiTree root)
{
    if(root!=NULL)
    {
        InOrder(root->LChild);
        printf("%c",root->data);
        InOrder(root->RChild);
    }
}
void PostOrder(BiTree root)
{
    if(root!=NULL)
    {
        PostOrder(root->LChild);
        PostOrder(root->RChild);
        printf("%c",root->data);
    }
}
void PreTreeDepth(BiTree bt,int h)
 
{ int depth=0;
    if(bt!=NULL)
    {   
        if(h>depth) depth=h;
        PreTreeDepth(bt->LChild,h+1);
        PreTreeDepth(bt->RChild,h+1);
    }
}
void leaf(BiTree root)
   
{   int LeafCount=0;
    if(root!=NULL)
    {
        leaf(root->LChild);
        leaf(root->RChild);
        if(root->LChild==NULL&&root->RChild ==NULL)
            LeafCount++;
    }
}
void mainscreen()
{
printf("\n=========第三次实验--树与二叉树操作============");
    printf("\n===============================================");
    printf("\n==1.生成二叉树                               ==");
    printf("\n==2.先序遍历                                 ==");
    printf("\n==3.中序遍历                                 ==");
    printf("\n==4.后序遍历                                 ==");
    printf("\n==5.二叉树的深度                             ==");
    printf("\n==6.二叉树中叶子结点数                       ==");
    printf("\n==7.创建哈夫曼树                             ==");
    printf("\n==8.哈夫曼编码                               ==");
    printf("\n==0.退出                                     ==");
    printf("\n===============================================\n");
    printf("\n请输入你的选择:");
}
void main(){
CreateBiTree(&bt);
PreOrder(t);
InOrder(t);
InOder(t);
}
对这个我实在不会了。求助攻,把这个修改一下。谢谢
0 回复
1