请教一个二叉树的问题
#include<stdio.h>#include<malloc.h>
#include<iostream.h>
#define OK 1
#define ERROR 0
typedef int Status;
typedef char BiElemType;
typedef struct BiTNode
{
BiElemType data;
struct BiTNode *lchild,*rchild;
}BitNode,*BiTree;
Status CreateBiTree(BiTree &T)
{//先序创建二叉树
BiElemType ch;
scanf(&ch);
if(ch==' ') T=NULL;
else{
if(!(T=(BitNode *)malloc(sizeof(BitNode)))) return ERROR;
T->data=ch;
CreateBiTree(T->lchild);
CreateBiTree(T->rchild);
}
Status PrintElement(BiElemType e)
{
cout<<e<<' ';//错误信息local function definitions are illegal
}
Status PreOrderTraverse(BiTree T,Status(*visit)(BiElemType e))
{//先序遍历二叉树
if(T){
if((*visit)(T->data))
if(PreOrderTraverse(T->lchild,visit))
if(PreOrderTraverse(T->rchild,visit))
return OK;
return ERROR;
}
else return OK;
}//PreOrderTraverse
void main()
{
BiTree T;
Status(*visit)();
Status i,j;
i=CreateBiTree(T);
if(i)
j=PreOrderTraverse(T,PrintElement);//
else return;
}
下面是编译时产生的错误:
D:\c+++\MSDev98\MyProjects\二叉树\123.cpp(25) : error C2601: 'PrintElement' : local function definitions are illegal
D:\c+++\MSDev98\MyProjects\二叉树\123.cpp(29) : error C2601: 'PreOrderTraverse' : local function definitions are illegal
D:\c+++\MSDev98\MyProjects\二叉树\123.cpp(40) : error C2601: 'main' : local function definitions are illegal
D:\c+++\MSDev98\MyProjects\二叉树\123.cpp(50) : fatal error C1004: unexpected end of file found
怎么老是说函数定义不合法呢?再是函数指针做函数参数怎么样?
请大虾们帮帮忙..