利用顺序栈的操作函数
typedef char SElemType;
#include"Stack.h"
int kuohaopipei()
{
char p;
SqStack s;
char temp;
InitStack(s);
p=getchar();
while(p!='\n')
{
if(p=='('||p=='['||p=='{')
Push(s,p);
else if(p==')'||p==']'||p=='}')
{
if(StackEmpty(s)) return ERROR;
Pop(s,temp);
if(p==')'&&temp!='(') return ERROR;
if(p==']'&&temp!='[') return ERROR;
if(p=='}'&&temp!='{') return ERROR;
}
p=getchar();
}
if(!StackEmpty(s)) return ERROR;
return OK;
}
测试函数的代码:
int main()
{
if(kuohaopipei()==OK)
printf("TRUE\n");
else
printf("FALSE\n");
return 0;
}