| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 557 人关注过本帖
标题:大家帮帮忙看看错在哪?谢谢啦!
只看楼主 加入收藏
chenwei926fl
Rank: 1
来 自:宜昌
等 级:新手上路
帖 子:16
专家分:0
注 册:2013-4-4
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:1 
大家帮帮忙看看错在哪?谢谢啦!
#include<stdio.h>
#include<stdlib.h>
typedef int DataType;
typedef struct node
{
    DataType data;
    struct node *LChild;
    struct node *RChild;
}BiTNode,*BiTree;
typedef struct
void CreBiTree(BiTree *bt)
{
    char ch;
    rewind(stdin);
    ch=getchar();
    if(ch=='.') *bt=NULL;
    else
    {
        *bt=(BiTree)malloc(sizeof(BiTNode))
        (*bt)->data=ch;
        CreBiTree(&((*bt)->LChild));
        CreBiTree(&((*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);
    }
}
int PostBiTreeDepth(BiTree root)
{
    int hl,hr,max;
    if(bt!=NULL)
    {
        hl=PostBiTreeDepth(root->LChild);
        hr=PostBiTreeDepth(root->RChild);
        max=hl>hr?hl:hr;
        return(max+1);
    }
    else
        return(0);
}
int Leaf(BiTree root)
{
    int LeafCount=0;
    if(root!=NULL)
    {
        Leaf(root->LChild);
        Leaf(root->RChild);
        if(root->LChild==NULL&&root->RChild==NULL)
            LeafCount++;
    }
    return(LeafCount);
}
int Bit(BiTree bt)
{
    int bit=0;
    if(bt!=NULL)
    {
        Bit(bt->LChild);
        Bit(bt->RChild);
        bit++;
    }
    return(bit);
}

void main()
{
    int i,flag=1;
    int d,b;
    BiTree T;
    printf("二叉树演示过程\n");
    printf("1.二叉树创建\n");
    printf("2.二叉树遍历\n");
    printf("3.二叉树属性\n");
        printf("4.创建哈夫曼树\n");
        printf("5.哈夫曼编码\n");
    printf("6.退出\n");
    printf("\n");
    while(flag)
    {
        rewind(stdin);
        printf("1-6 请选择:");
        scanf("%d",&i);
        switch(i)
        {
            case 1:
                printf("输入元素:");
                CreBiTree(&T);
                break;
            case 2:
                printf("先序遍历!");
                PreOrder(T);
                printf("\n");
                printf("中序遍历!");
                InOrder(T);
                printf("\n");
                printf("后序遍历!");
                PostOrder(T);
                printf("\n");
                break;
            case 3:
                {
                printf("树的属性:\n");
                d=PostBiTreeDepth(T);
                printf("树的深度 %d\n",d);
                b=Bit(T);
                printf("树的结点数 %d\n",b);
                printf("叶子结点%d\n",Leaf(T));
                break;
                }
            case 4:
                {
                    flag=1;break;
                }
        }
    }
}
        




   
搜索更多相关主题的帖子: 看看 谢谢 include 
2013-05-15 21:37
邓士林
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:淮河河畔
等 级:贵宾
威 望:61
帖 子:2392
专家分:13384
注 册:2013-3-3
收藏
得分:20 
*bt=(BiTree)malloc(sizeof(BiTNode))
         (*bt)->data=ch;
这里的问题

Maybe
2013-05-16 14:09
快速回复:大家帮帮忙看看错在哪?谢谢啦!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017460 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved