这个算法我运行不了,不知道怎么找错!
#define TRUE 1
#define FLASE 0
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef int Status
#include<stdio.h>
#include"Status.h"
#include<stdlib.h>
#define STACK_INIT_SIZE 100;
#define STACKINCREMENT 10;
typedef char SElemType
typedef struct{
SElemType *base;
SElemType *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,SElemType &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;
}
Status StackEmpty(SqStack S){
if(S.top==S.base)return TRUE;
return FLASE;
}
#include"Stack.cpp"
#include"Status.h"
#include<stdio.h>
Status MatchBracket(char *ch)
{ SqStack S; InitStack(S);
while (ch[i]!='\0'){
if (ch[i]=='['||ch[i]=='(') Push(S,ch[i]);
else if (ch[i]==']'||ch[i]==')')
if (GetTop(S,ch1))
if ((ch1=='['&&ch[i]==']')||(ch1=='('&&ch[i]==')'))
Pop(S,ch1);
else return ERROR;
else return ERROR;
i++; }
if (!StackEmpty(S)) return ERROR;
return OK;
}
void main()
{
char a[],i=0,ch;
printf("请输入算式:\n");
while((ch=getchar())!='\n')
{
a[i++]=ch;
}
MatchBracket(a);
}