#include <stdio.h>
#include <iostream>
#include <string>
#include <cstring>
#define InitSize 10
typedef struct
{
char *base;
int top;
} SeqStack;
void PrintStack(SeqStack s);
const char *InitStack(SeqStack &S)
{
S.base = new char[InitSize];
S.top = -1;
return "成功";
}
bool IsEmptyStack(SeqStack s)
{
return s.top == -1;
}
bool Push(SeqStack &s, char e)
{
if (s.top == InitSize - 1)
{
return false;
}
s.base[++s.top] = e;
return true;
}
bool PopStack(SeqStack &s, char &e)
{
if (s.top == -1)
{
return false;
}
e = s.base[s.top--];
return true;
}
bool IsHuiWen(SeqStack &s, char *t)
{
InitStack(s);
int len = strlen(t);
int i;
for (i = 0; i < len / 2; i++)
{
Push(s, t[i]);
}
if (len % 2 != 0)
{
i++;
}
while (!IsEmptyStack(s))
{
char temp;
PopStack(s, temp);
if (temp != t[i])
{
return false;
}
else
i++;
}
return true;
}
void PrintStack(SeqStack s)
{
for (int i = 0; i <= s.top; i++)
{
printf("%c", s.base[i]);
}
}
int main()
{
SeqStack S;
char t[] = "abdefdba";
if (IsHuiWen(S, t))
{
printf("是回文!");
}
else
printf("不是回文!");
}