大侠们来解释下VC++6.0编译过不去的原因可以吗?
#include<stdio.h>#include<stdlib.h>#define NULL 0typedef char type;typedef struct node{ type date; int ltag,rtag; struct node *lchild,*rchild;}node,*tree;tree pre;tree greetree()///////////////////////建立2叉树{ type x; tree bt; scanf("%c",&x); getchar(); if(x=='0') { bt=NULL; } else { bt=(tree)malloc(sizeof(node)); bt->date=x; bt->lchild=greetree(); bt->rchild=greetree(); } return bt;}preeorder(tree T)///////////线索化{ tree thrt; thrt=(tree)malloc(sizeof(node)); thrt->ltag=0;thrt->rtag=1;thrt->rchild=thrt; if(!T) thrt->lchild=thrt; else { thrt->lchild=T;pre=thrt; preethreading(T); printf("xx\n"); pre->rchild=thrt; pre->rtag=1; thrt->rchild=pre; }} preethreading(tree p)/////////////////接上{ if(p) { preethreading(p->lchild); if(!p->lchild) { p->ltag=1;p->lchild=pre;} else p->ltag=0; if(!pre->rchild) { pre->rtag=1; pre->rchild=p;} else p->rtag=0; pre=p; if(p->ltag==0) preethreading(p->lchild); preethreading(p->rchild); } }main(){ tree s; s=greetree(); preeorder(s); }
#include<stdio.h>#include<stdlib.h>#define NULL 0typedef char type;typedef struct node{ type date; int ltag,rtag; struct node *lchild,*rchild;}node,*tree;tree pre;tree greetree()///////////////////////建立2叉树{ type x; tree bt; scanf("%c",&x); getchar(); if(x=='0') { bt=NULL; } else { bt=(tree)malloc(sizeof(node)); bt->date=x; bt->lchild=greetree(); bt->rchild=greetree(); } return bt;}preethreading(tree p)/////////////////接上{ if(p) { if(!p->lchild) { p->ltag=1;p->lchild=pre;} else p->ltag=0; if(!pre->rchild) { pre->rtag=1; pre->rchild=p;} else p->rtag=0; pre=p; if(p->ltag==0) preethreading(p->lchild); preethreading(p->rchild); } }preeorder(tree T)///////////线索化{ tree thrt; thrt=(tree)malloc(sizeof(node)); thrt->ltag=0;thrt->rtag=1;thrt->rchild=thrt; if(!T) thrt->lchild=thrt; else { thrt->lchild=T;pre=thrt; preethreading(T); printf("xx\n"); pre->rchild=thrt; pre->rtag=1; thrt->rchild=pre; }}void main(){ tree s; s=greetree(); preeorder(s); }
[解决办法]
1、你的函数都没有返回值,严格来讲是错的
2、虽然写在main()前面不需要声明了,可是你存在这函数之间的调用啊,也就是说,在第一个函数里面调用了第三
个,可是第三个那个时候还没定义呢,所以会报错...
建议还是写函数声明吧,按规矩做事。虽然语法那样规定,但是世纪中很少那样写,原因很简单,基于“接口与实现
分离”的原则,函数声明都是放在头文件中的!