标题:二叉树的创建及其遍历
只看楼主
WL2311296974
Rank: 1
来 自:安徽
等 级:新手上路
帖 子:37
专家分:7
注 册:2017-3-30
结帖率:90%
已结贴  问题点数:10 回复次数:3 
二叉树的创建及其遍历

编译的时候总是出现这个错误:[Error] ld returned 1 exit status

哪位大神帮忙看看!!!


#define _CRT_SECURE_NO_WARNINGS
#include "stdio.h"
#include "malloc.h"
#include "stdlib.h"
#define OK 1
#define ERROR 0
#define  OVERFLOW -2
typedef int Status;
typedef char ElemType;
typedef struct BTNode
{
    ElemType data;
    struct BTNode *lchild,*rchild;
}BTNode,*BTree;

Status CreatBtree(BTree *T);
Status PreOrderTraverse_Recursive(BTree T,Status(*Visit)(ElemType e));
Status InOrderTraverse_Recursive(BTree T,Status(*Visit)(ElemType e));
Status PostOrderTraverse_Recursive(BTree T,Status(*Visit)(ElemType e));
Status PrintElement(ElemType e);

Status CreatBtree(BTree *T)
{
    char ch;
    scanf("%c",&ch);
    if(ch==' ')
    {
        (*T)=NULL;
    }
    else
    {
        if(!((*T)=(BTree)malloc(sizeof(BTNode))))
        exit(OVERFLOW);
        (*T)->data=ch;
        CreatBTree(&((*T)->lchild));
        CreatBTree(&((*T)->rchild));
    }
        return OK;
        
}
Status PreOrderTraverse_Recursive(BTree T,Status(*Visit)(ElemType e))
{
    if(T)
    {
        if(Visit(T->data));
        if(PreOrderTraverse_Recursive(T->lchild,Visit))
        if(PreOrderTraverse_Recursive(T->rchild,Visit))
        return OK;
        return ERROR;
    }
    else
    {
        return OK;
    }
}
Status InOrderTraverse_Recursive(BTree T,Status(*Visit)(ElemType e))
{
if(T)
    {
        if(InOrderTraverse_Recursive(T->lchild,Visit))
        if(Visit(T->data));
        if(InOrderTraverse_Recursive(T->rchild,Visit))
        return OK;
        return ERROR;
    }
    else
    {
        return OK;
    }
}
Status PostOrderTraverse_Recursive(BTree T,Status(*Visit)(ElemType e))
{
if(T)
    {
        if(PostOrderTraverse_Recursive(T->lchild,Visit))
        if(PostOrderTraverse_Recursive(T->rchild,Visit))
        if(Visit(T->data));
        return OK;
        return ERROR;
    }
    else
    {
        return OK;
    }
}
Status PrintElement(ElemType e)
{
    putchar(e);
    return OK;
}
int main()
{
    BTree T;
    CreatBTree(&T);
    PreOrderTraverse_Recursive(T,PrintElement);
    putchar('\n');
    InOrderTraverse_Recursive(T,PrintElement);
    putchar('\n');
    PostOrderTraverse_Recursive(T,PrintElement);
    putchar('\n');
    return 0;
}
   
搜索更多相关主题的帖子: include status 二叉树 
2017-06-03 20:29
林月儿
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:湖南
等 级:版主
威 望:138
帖 子:2276
专家分:10647
注 册:2015-3-19
得分:10 
Status CreatBtree(BTree *T);
Status PreOrderTraverse_Recursive(BTree T,Status(*Visit)(ElemType e));
Status InOrderTraverse_Recursive(BTree T,Status(*Visit)(ElemType e));
Status PostOrderTraverse_Recursive(BTree T,Status(*Visit)(ElemType e));
Status PrintElement(ElemType e);

Status CreatBtree(BTree *T)
{
    char ch;
    scanf("%c",&ch);
    if(ch==' ')
    {
        (*T)=NULL;
    }
    else
    {
        if(!((*T)=(BTree)malloc(sizeof(BTNode))))
        exit(OVERFLOW);
        (*T)->data=ch;
        CreatBTree(&((*T)->lchild));
        CreatBTree(&((*T)->rchild));
    }
        return OK;
   

。。。。

int main()
{
    BTree T;
    CreatBTree(&T);
    PreOrderTraverse_Recursive(T,PrintElement);
    putchar('\n');
    InOrderTraverse_Recursive(T,PrintElement);
    putchar('\n');
    PostOrderTraverse_Recursive(T,PrintElement);
    putchar('\n');
    return 0;
}

剑栈风樯各苦辛,别时冰雪到时春
2017-06-03 21:00
WL2311296974
Rank: 1
来 自:安徽
等 级:新手上路
帖 子:37
专家分:7
注 册:2017-3-30
得分:0 
好了   谢谢!!!

我的类不是你的泪
2017-06-03 21:19
林月儿
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:湖南
等 级:版主
威 望:138
帖 子:2276
专家分:10647
注 册:2015-3-19
得分:0 
感觉有点不对劲,,

剑栈风樯各苦辛,别时冰雪到时春
2017-06-03 21:44



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




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

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