求助算法编译问题
gcc4.2.4 Ubuntu 下的编译器
下列代码……报错
#include "stdlib.h"
#include "stdio.h"
#define ERROR 0
#define OVERFLOW -2
#define OK 1
typedef int Status;
typedef char ElemType ;
typedef struct BiTree{
ElemType data;
struct BiTree *lchild, *rchild;
} *BiTree,BIT;
Status CreateBiTree(BiTree T)
{ char ch;
scanf("%c",&ch);
if(ch=='*') T=NULL;
else {
if(!(T=(BiTree)malloc(sizeof(BIT)))) exit(OVERFLOW);
T->data=ch;
CreateBiTree(T->lchild);
CreateBiTree(T->rchild);
};
return OK;
};
int Visit (ElemType e)
{
printf("%c",e);
return OK;
};
Status PreOrderTraverse ( T){
if(T){
if(Visit(T->data))
if(PreOrderTraverse(T->lchild))
if(PreOrderTraverse(T->rchild)) return OK;
return ERROR;
} else return OK;
};
Status InOrderTraverse ( T){
if(T){
if(InOrderTraverse(T->lchild))
if(Visit(T->data))
if(InOrderTraverse(T->rchild)) return OK;
return ERROR;
} else return OK;
};
Status PostderTraverse (T){
if(T){
if(PostOrderTraverse(T->lchild))
if(Visit(T->data))
if(PostOrderTraverse(T->rchild)) return OK;
return ERROR;
} else return OK;
};
main()
{
CreateBiTree ();
PreOrderTraverse ();
InOrderTraverse();
PostderTraverse();
}
错误代码
20091176@calcium:~/project$ gcc -o tree tree.c
In file included from /usr/include/stdio.h:34,
from tree.c:2:
tree.c:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before string constant
In file included from /usr/include/stdio.h:75,
from tree.c:2:
/usr/include/libio.h:332: error: expected specifier-qualifier-list before ‘size_t’
/usr/include/libio.h:364: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/libio.h:373: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/libio.h:493: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘_IO_sgetn’
In file included from tree.c:2:
/usr/include/stdio.h:312: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdio.h:319: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdio.h:361: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdio.h:363: error: format string argument not a string type
/usr/include/stdio.h:365: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdio.h:367: error: format string argument not a string type
/usr/include/stdio.h:678: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fread’
/usr/include/stdio.h:684: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fwrite’
/usr/include/stdio.h:706: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fread_unlocked’
/usr/include/stdio.h:708: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fwrite_unlocked’
tree.c: In function ‘CreateBiTree’:
tree.c:19: warning: incompatible implicit declaration of built-in function ‘malloc’
tree.c:19: warning: incompatible implicit declaration of built-in function ‘exit’
tree.c: In function ‘PreOrderTraverse’:
tree.c:34: error: invalid type argument of ‘->’
tree.c:35: error: invalid type argument of ‘->’
tree.c:36: error: invalid type argument of ‘->’
tree.c: In function ‘InOrderTraverse’:
tree.c:44: error: invalid type argument of ‘->’
tree.c:45: error: invalid type argument of ‘->’
tree.c:46: error: invalid type argument of ‘->’
tree.c: In function ‘PostderTraverse’:
tree.c:53: error: invalid type argument of ‘->’
tree.c:54: error: invalid type argument of ‘->’
tree.c:55: error: invalid type argument of ‘->’
tree.c: In function ‘main’:
tree.c:62: error: too few arguments to function ‘CreateBiTree’
求指教
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
写的真乱。
这儿的T是神马?
函数结束的}后为嘛加个;?
不光语法上有问题,逻辑上也混乱:CreateBiTree,这个函数你没有返回一个节点,无论是通过返回值还是通过参数输出。
懒得看了。