烟台大学
吴玉然
题目 括号的匹配
#include <stdio.h>
#include "linkstnode.h"
int main()
{ ElemType c;
LinkStNode *q;
int d=1;
char st[50];
InitStack(q);
printf("请输入表达式:");
scanf("%s",st);
for(int i=0; st[i]!='\0'; i++)
{
switch(st[i])
{
case'(':
case'[':
case'{':
Push(q, st[i]);
break;
case')':
if(StackEmpty(q))
break;
else
{
Pop(q, c);
if(c!='(') d=0;
break;
}
case']':
if(StackEmpty(q))
break;
else
{
Pop(q, c);
if(c!='[') d=0;
break;
};
case'}':
if(StackEmpty(q))
break;
else
{
Pop(q, c);
if(c!='{') d=0;
break;
}
}
}