下面代码为啥会报这样的错?
#pragma once
#include<stdio.h>
#include<stdlib.h>
#define _CRT_SECURE_NO_WARNINGS
#define MaxSize 1024
//typedef char ElemType;
typedef struct node
{
char data;
struct node* lchild;
struct node* rchild;
}BTNode;
typedef BTNode* ElemType;
typedef struct
{
ElemType data[MaxSize];
int top;
}SqStack;
//初始化栈
void InitStack(SqStack*& q);
//销毁栈
void DestroyStack(SqStack*& q);
//判断栈是否为空
bool EmptyStack(SqStack* q);
//进栈
bool Push(SqStack*& q, ElemType e);
//出栈
bool Pop(SqStack*& q, ElemType& e);
//取栈顶元素
bool GetTop(SqStack* q, ElemType& e);
//树
void CreateBT(BTNode*& b, char* str);
void DispBT(BTNode* b);
BTNode* FindNode(BTNode* b, char e);
void DispChild(BTNode* t);
int BTHeight(BTNode* b);
int NodeNum(BTNode* b);
void PreOrder(BTNode* b);
SqStack.cpp
#include"BTree.h"
void InitStack(SqStack*& q)
{
q->top = -1;
}
void DestroyStack(SqStack*& q)
{
free(q);
}
bool EmptyStack(SqStack* q)
{
/*if (q->top == -1)
{
return true;
}
else
{
return false;
}*/
return q->top == -1;
}
bool Push(SqStack*& q, ElemType e)//名字都写反
{
if (q->top == MaxSize - 1)
{
return false;
}
/*q->top++;
q->data[q->top] = e;*/
q->data[++q->top] = e;
return true;
}
bool Pop(SqStack*& q, ElemType& e)
{
if (q->top == -1)
{
return false;
}
/*e = q->data[q->top];
q->top--;*/
e = q->data[q->top--];
return true;
}
bool GetTop(SqStack* q, ElemType& e)
{
//if (EmptyStack)
if (EmptyStack(q))
{
return false;
}
e = q->data[q->top];
return true;
}
BTree.cpp
#include"BTree.h"
void CreateBT(BTNode*& b, char* str)
{
BTNode* p = NULL;
b = NULL;
BTNode* St[MaxSize];
int top = -1;
int k = 0;
while (*str != '\0')
{
switch (*str)
{
case '(':
top++;
St[top] = p;
k = 1;
break;
case ')':
top--;
break;
case ',':
k = 2;
break;
default:
p = (BTNode*)malloc(sizeof(BTNode));
p->data = *str;
p->lchild = p->rchild = 0;
if (b == NULL)
{
b = p;
}
else
{
switch (k)
{
case 1:
St[top]->lchild = p;
break;
case 2:
St[top]->rchild = p;
break;
default:
break;
}
}
break;
}
str++;
}
}
void DispBT(BTNode* b)
{
if (b != NULL)
{
printf("%c", b->data);
if (b->lchild != NULL || b->rchild != NULL)
{
printf("(");
DispBT(b->lchild);
if (b->rchild != NULL)
{
printf(",");
}
DispBT(b->rchild);
printf(")");
}
}
}
BTNode* FindNode(BTNode* b, char e)
{
/*BTNode* p = NULL;
if (b == NULL)
return NULL;
if (b->data == e)
{
return b;
}
p = FindNode(b->lchild, e);
p = FindNode(b->rchild, e);
if(p != NULL)
return p;
else
return NULL;*/
BTNode* p = NULL;
if (b == NULL)
{
return NULL;
}
else if (b->data == e)
{
p = FindNode(b->lchild, e);
if (p != NULL)
{
return b;
}
else
{
return FindNode(b->rchild, e);
}
}
}
void DispChild(BTNode* t)
{
printf("%c的左孩子为:%c\n", t->data, t->lchild->data);
printf("%c的左孩子为:%c\n", t->data, t->rchild->data);
}
//int BTHeight(BTNode* b)
//{
// int lheight = 0;
// int rheight = 0;
// if (b->lchild == NULL && b->rchild == NULL)
// {
// return 0;
// }
// return (lheight > rheight ? (lheight + 1) : (rheight + 1));
//}
int BTHeight(BTNode* b)
{
int lheight = 0;
int rheight = 0;
if (b == NULL)
{
return 0;
}
else
{
BTHeight(b->lchild);
BTHeight(b->rchild);
return (lheight > rheight ? (lheight + 1) : (rheight + 1));
}
}
int NodeNum(BTNode* b)
{
if (b == NULL)
{
return 0;
}
else
{
int lnum = NodeNum(b->lchild);
int rnum = NodeNum(b->rchild);
return lnum + rnum;
}
}
void PreOrder(BTNode* b)
{
//递归方法
/*if (b != NULL)
{
printf("%c", b->data);
PreOrder(b->lchild);
PreOrder(b->rchild);
}*/
//非递归方法
BTNode* p;
SqStack* st;
InitStack(st);
if (b != NULL)
{
Push(st, b);
while (!EmptyStack(st))
{
Pop(st, p);
printf("%c", p->data);
if (p->rchild != NULL)
{
Push(st, p->rchild);
}
if (p->lchild != NULL)
{
Push(st, p->lchild);
}
}
printf("\n");
}
DestroyStack(st);
}
你的main入口呢,你在哪里调用了dispBTNode方法