二叉树的创建及其遍历
编译的时候总是出现这个错误:[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;
}