查找程序错误原因
#include <stdio.h>#include <malloc.h>
#include <string.h>
#define Maxsize 50
typedef char ElemType;
typedef struct node
{
ElemType data; /*数据元素*/
struct node *lchild; /*指向左孩子*/
struct node *rchild; /*指向右孩子*/
} BTNode;
void CreateBTNode(BTNode *&t,char *str);
{
BTNode *st[Maxsize],*p=NULL;
int top=-1,k,j=0;
char ch;
t=NULL;
ch=str[j];
while(ch!='\0')
{
switch(ch)
{
case '(':top++;st[top]=p;k=1;break;
case')':top--;break;
case',':k=2;break;
default:p=(BTNode *)malloc(sizeof(BTNode));
p->data=ch;p->lchild=p->rchild=NULL;
if(t==NULL)
t=p;
else
{
switch(k)
{
case 1:st[top]->lchild=p;break;
case 2:st[top]->rchild=p;break;
}
}
}
j++;
ch=str[j];
}
}
/*按照中序非递归遍历二叉树 */
void InOrder(BTNode *t)
{
BTNode *st[Maxsize],*p;
int top=-1;
if(t!=NULL)
{
p=t;
while (top>-1 || p!=NULL)
{
while(p!=NULL)
{
top++;
st[top]=p;
p=p->lchild;
}
if(top>-1)
{
p=st[top];
top--;
printf("%c",p->data);
p=p->rchild;
}
}
printf("\n");
}
}
/*递归法求叶子结点个数*/
int leavesSum(BTNode *t)
{
if (t==NULL)
{
return 0;
}
if (t->lchild==NULL && t->rchild==NULL)
return 1;
return leavesSum(t->lchild)+leavesSum(t->rchild);
}
void main()
{
BTNode *t;
CreateBTNode(t,"A(B(D(,G)),C(E,F))");
InOrder(t);
printf("二叉树t的叶子结点个数:%d\n",leavesSum(t));
printf("\n");
}
--------------------Configuration: 4 - Win32 Debug--------------------
Compiling...
4.cpp
E:\数据结构\实验4\4.cpp(15) : error C2447: missing function header (old-style formal list?)
执行 cl.exe 时出错.
4.obj - 1 error(s), 0 warning(s)