以栈实现括号匹配问题
#include<stdio.h>
struct node //在某些编译平台上不添加名称便会显示编译错误{
char a[200];
int top;
}op;
bool match(char *exp)
{
op.top=-1;
while(*exp!='\0')
{
if(*exp=='['||*exp=='(')
{
op.top++;
op.a[op.top]=*exp;
exp++;
}
else if(*exp==']')
{
if(op.a[op.top]=='[')
{
op.top--;
exp++;
}
else
return false;
}
else if(*exp==')')
{
if(op.a[op.top]=='(')
{
op.top--;
exp++;
}
else
return false;
}
}
if(op.top==-1)
return true;
else
return false;
}
int main()
{
char exp[200];
scanf("%s",exp);
if(match(exp))
printf("YES");
else
printf("NO");
return 0;
}