#include <iostream>
#define MaxSize 50
#include<string.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
typedef char ElemType;
typedef struct //队列的结构
{
ElemType data[MaxSize];
int front ,rear;
} SqQueue;
//初始化队列
void InitQueue(SqQueue * &q)
{
q=(SqQueue * )malloc(sizeof(SqQueue));
q->front=q->rear=0;
}
//销毁队列
bool DestroyQueue(SqQueue * q )
{
free(q);
return true;
}
//判断队列是否为空的
bool QueueEmpty(SqQueue * q )
{
return(q->front==q->rear);
}
//进队列
bool enQueue(SqQueue * &q, ElemType e )
{
if((q->rear+1)%MaxSize==q->front)
return false ;
q->rear=(q->rear+1)%MaxSize;
q->data[q->rear]=e;
return true;
}
//出队列
bool deQueue(SqQueue * &q ,ElemType &e )
{
if (q->rear==q->front)
return false ;
q->front=(q->front+1)%MaxSize;
e=q->data[q->front];
return true;
}
typedef struct //顺序栈的结构
{
ElemType data[MaxSize];
int top;
} SqStack ;
//初始化栈
void InitStack (SqStack * &s )
{
s=(SqStack *)malloc (sizeof(SqStack));
s->top=-1;
}
//销毁栈
void DestroyStack(SqStack * &s )
{
free(s);
}
//判断栈是否为空
bool StackEmpty(SqStack * s )
{
return (s->top==-1);
}
//进栈
bool Push(SqStack * & s ,ElemType e)
{
if(s->top==MaxSize-1)
return false ;
s->top++;
s->data[s->top]=e;
return true;
}
//出栈
bool Pop(SqStack * & s ,ElemType & e )
{
if(s->top==-1)
return false;
e=s->data[s->top];
s->top--;
return true ;
}
//取栈顶元素
bool GetTop(SqStack *s ,ElemType & e )
{
if (s->top==-1)
return false ;
e=s->data[s->top];
return true ;
}
int main()
{
SqStack *s;
SqQueue *q;
ElemType e ,r;
char a[50];
int i,len;
InitQueue(q);
InitStack(s);
printf("请你输入需要检验的回文字符:\n");
scanf("%s",a);
len=strlen(a); //统计长度
for(i=0;i<len;i++)
{
Push(s,a[i]);
enQueue(q,a[i]);
}
bool p=true ;
int j;
while( j<len)
{
deQueue(q,e);
Pop(s,r);
if(r==e)
{
j++;
}
else
{
printf("这不是回文字符\n");
p=false;
break;
}
}
DestroyQueue(q);
DestroyStack(s);
if(p)
printf("这是回文字符\n");
return 0;
}