/*烟台大学计算机学院
文件名称:kuohaodepipei
作者:董玉祥
完成日期: 2017 10 15
问题描述:括号的匹配(栈)
*/
问题及代码:
#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;
}
}
}
运行结果截图: