堆栈做了个检验括号是否匹配的程序,不知错哪 。 求指点错在哪里 语法可能有错
// 括号匹配.cpp : Defines the entry point for the console application.//用堆栈的方式实现括号的配对问题
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define STACK_INIT_SIZE 100; //存储空间初始分量为100
#define STACKINCREMENT 10; //存储空间分配增量为10
typedef struct stack
{
char *base;
char *top;
int stacksize;
}SqStack;
Status InitStack(SqStack &s) //构造空栈
{
s.base = (SElemType *)malloc(STACK_INIT_SIZE * sizeof(SElemType));
if(!s.base) exit (OVERFLOW);
s.top = s.base;
s.stacksize = STACK_INIT_SIZE;
return OK;
}
Status GetTop(SqStack s,SElemTyop &e) //判定栈是否为空,若空报错
{
if(s.top == s.base) return ERROR;
e = *(s.top-1);
return OK;
}
Status Push(SqStack &s,SElemtype e) //压栈
{
if(s.top -s.base >= s.stacksize) // 栈满,加空间
{
s.base = (SElemType *)realloc(s.base,(s.stacksize +STACKINCREMENT) * sizeof(SElemtype));
if(!s.base) exit (OVERFLOW); //存储分配失败
s.top = s.base+s.stacksize;
s.stacksize += STACKINCREMENT;
}
*s.top++ = e;
return OK;
}
Status Pop(SqStack &s,SElemtype &e) //出栈
{
if(s.top =s.base) return ERROR;
e = * --s.top;
return OK;
}
Bool Brackets Correspondency(char a[])
{
int i=0;
stack s;
Initstack(s);
Elemtype x;
printf("请输入带括号字符串:\n");
scanf("%s",a[]);
while(a[i])
{
switch(a[i])
{
case '(' : Push(s,a[i]); break;
case '[' : Push(s,a[i]); break;
case ')' : GetTop(s,x);
if (x=='(') Pop(s,x);
else return ERROR;break;
case ']' : GetTop(s,x);
if (x=='[') Pop(s,x);
else return ERROR;break;
default;
}
i++;
}
if(s.size !=0) return ERROR;
return OK;
}
int main()
{
Sqstack s;
InitStack(s);
if(Bool Brackets Correspondency(char a[]))
printf("括号匹配\n");
else
printf("括号不匹配!\n");
free(s.base);
return 0;
}
错误提示d:\工作学习\c\括号匹配\括号匹配.cpp(94) : fatal error C1010: unexpected end of file while looking for precompiled header directive
执行 cl.exe 时出错.