帮我改个写好的程序,谢谢
#include "stdafx.h"#include<stdio.h>
#include<stdlib.h>
#define stackLen 100;
typedef struct CheckStack
{
int top_;
int bottom_;
char data[stackLen];
} CheckStack;
void init(CheckStack s)
{
top_ = bottom_ = -1;
}
int empty(CheckStack s)
{
return (top_ == bottom_);
}
int top(CheckStack s)
{
if (empty(s)) return -1;
return s.data[top_];
}
int push(CheckStack s, char c)
{
if (top_ == stackLen-1) return -1;
s.data[top_++] = c;
return 0;
}
char pop(CheckStack s)
{
if (top_ == bottom_) return '\0';
return s.data[top_--];
}
int main()
{
CheckStack checkStack;
char buf[stackLen] = {0};
init(checkStack);
gets(buf);
for (int i=0; i<stackLen && buf[i] != 0; i++)
{
switch (buf[i])
{
case '[':
case '(':
push(checkStack, buf[i]);
break;
case ']':
if (top(checkStack) != '[')
{
printf("此串括号匹配不合法\n");
return 0;
}
pop(checkStack);
break;
case ')':
if (top(checkStack) != '(')
{
printf("此串括号匹配不合法\n");
return 0;
}
pop(checkStack);
break;
defaut:
break;
}
}
if (empty(checkStack))
printf("匹配\n");
else
printf("此串括号匹配不合法\n");
return 0;
}
/*把输入的符号读进来,如果是[,(,就直接入栈,如果是],),就判断栈顶字符是否是匹配的。、
如果不匹配,打印错误,退出;如果匹配,就把栈顶字符出栈。
全部输入完成后,最后判断栈是否为空。如果为空,就是匹配了,否则打印不匹配。*/