用栈来判断是否为回文的问题
											具体题目:试写一个算法,识别依次读入的一个以“#”为结束符的字符序列是否为形如“序列1@序列2”模式的字符序列。其中序列1和序列2中都不含字符“@”,且序列2是序列1的逆序列。例如,“a+b@b+a”是属于该模式的字符序列,而“1+3@3-1”则不是。现在的问题就是除了输入“@”是yes,输入其他的输出都是no,找不出是什么原因,希望各位大神能帮我看看
我写的代码如下
 程序代码:
程序代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MaxSize 100
struct SqStack
{
    char data[MaxSize];
    int top; //栈顶指针
};
void InitStack(SqStack *&s)//初始化栈
{
    s=(SqStack *)malloc(sizeof(SqStack));
    s->top=-1;
}
char Push(SqStack *s,char e)//进栈
{
    if(s->top==MaxSize-1)
        return 1;
    else
    {
        s->top++;
        s->data[s->top]=e;
    }
    return 0;
}
char Pop(SqStack *s)//出栈
{
    return(s->data[s->top--]);
}
int main()
{
    int i=0;
    char e;
    SqStack *s;
    char str[MaxSize];
    InitStack(s);
    printf("请输入一个字符串:\n");
    scanf("%s",&str);
    // 先将‘@’前的字母入栈
    while(str[i]!='\0'&&str[i]!='@')
    {
        Push(s,e);
        i++;
    }
    // 如果字符串中 没有出现 ‘@’返回no
    if(str[i]=='\0')
    return (printf("no"));
    i++;// i 定位到 & 后面第一个字符处
    while(str[i]!='\0'&&s->top!=-1)
    {
        char data=Pop(s);
        if(data==str[i])
        i++;
        else return (printf("no"));
    }
    // 如果正好相同就返回yes
    if(str[i]=='\0'&&s->top==-1)
    return (printf("yes"));
    else return (printf("no"));
}
										
					
	


 
											





 
	    

 
	


