标题:看看先序创建,遍历二叉树哪错了,谢谢!?
取消只看楼主
zhufeifei
Rank: 1
等 级:新手上路
威 望:2
帖 子:402
专家分:0
注 册:2006-8-11
 问题点数:0 回复次数:0 
看看先序创建,遍历二叉树哪错了,谢谢!?
#include<stdio.h>
typedef char TElemType;
typedef struct BiTNode
{
        TElemType data;
        struct BiTNode *lchild, *rchild;
}BiTNode, *BiTree;

/*递归创建一个二叉树*/
void createBiTree(BiTree t)
{
        char c;
        c = getchar();
        if(c == 's')
        {
                t = NULL;
        }
        else
        {
                t = (BiTree)malloc(sizeof(BiTNode));
                t -> data = c;
                createBiTree(t -> lchild);
                createBiTree(t -> rchild);
        }
}

/*先序遍历二叉树*/
void preOrder(BiTree t)
{
        if(t)
        {
            printf("%c", t -> data);
            preOrder(t -> lchild);
            preOrder(t -> rchild);
        }
        else
                printf("this is a empty tree!");
}
int main()
{
        BiTree t = NULL;
        clrscr();
        printf("create a tree:");
        createBiTree(t);
        printf("preOrder the tree:");
        preOrder(t);
        getch();
        return 0;
}
搜索更多相关主题的帖子: 二叉树 遍历 
2008-11-11 12:52



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-243608-1-1.html




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

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