该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#include
struct Listack{
char data;
struct Listack*next;};bool GetTop(Listack*&s,char e)
{
if(s->next==NULL){printf("incorrect"); return false;
}
if(e==s->next->data)
return true;
}
void Push(Listack* &s,char e)
{
Listack*p;
p=(Listack*)malloc(sizeof(Listack));
p->data=e;
p->next=s->next;
s->next=p;
}
bool StackEmpty(Listack*s)
{
return(s->next==NULL);
}
bool Pop(Listack*&s,char e)
{
Listack * p;
if(s->next==NULL)
{printf("incorrect"); return false;
}
p=s->next;
e=p->data;
s->next=p->next;
free(p);
return true;
}
void Match(char exp[])
{
Listack* st;
st=(Listack*)malloc(sizeof(Listack));
st->next=NULL;
char ch='(';int i;
for(i=0;exp[i]=='('||')';i++)
{if(exp[i]=='(')
Push(st,exp[i]);
else if(exp[i]==')')
{
if(GetTop(st,ch))
Pop(st,ch);
}
}
if(!StackEmpty(st))
printf("incorrect");
else printf("correct");
}int main()
{
char str[100];
printf("please input:");
gets(str);
Match(str);
}