求解!!!!顺序栈括弧匹配的检验问题,为什么运行结果总是“匹配”??
#include <stdio.h>#include <stdlib.h>
#define MaxSize 100
struct SeqStack
{
char data[MaxSize];
int top;
};
void InitSeqStack(struct SeqStack *pS)
{
pS->top=-1;
}
int IsEmpty(struct SeqStack *pS)
{
pS->top==-1;
return 1;
}
void PushSeqStack(struct SeqStack *pS,char item)
{
pS->top++;
pS->data[pS->top]==item;
}
char GetTop(struct SeqStack *pS)
{
pS->data[pS->top];
return 1;
}
char PopSeqStack(struct SeqStack *pS)
{
pS->top--;
pS->data[pS->top+1];
return 1;
}
int main()
{
struct SeqStack s;
char ch,x;
InitSeqStack(&s);
while((ch=getchar())!='\n')
{
if(ch=='('||ch=='[')
PushSeqStack(&s,ch);
if(ch==')'||ch==']')
{
x=GetTop(&s);
if(!IsEmpty(&s)&&x='('||!IsEmpty(&s)&&x=='[')
PopSeqStack(&s);
else
{
printf("不匹配\n");
return 0;
}
}
}
if(IsEmpty(&s))
printf("不匹配\n");
else
printf("匹配\n");
return 0;
}