试用栈作为数据结构,编写一个算法判别读入的一个以@为结束符的字符序列是否为回文
#include
#include
#include
int main()
{
int judgement(char c[]);
char*a="ababab@";
if(judgement(a))
printf("%s 是回文",a);
else
printf("%s 不是回文",a);
}
int judgement(char c[])
{
SqStack S;
LinkQueue Q;
SElemType e1;
QElemType e2;
int i;
InitStack(&S);
InitQueue(&Q);
for(i=0;c[i]!='0';i++)
{
Push(&S,c[i]);
EnQueue(&Q,c[i]);
}
while(!StackEmpty(S)&& !QueueEmpty(Q))
{
Pop(&S,&e1);
EnQueue(&Q,&e2);
if(e1!=e2)
return 0;
}
if(StackEmpty(S)&& QueueEmpty(Q))
return 1;
}