#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include <string.h>
//声名
#define MAXSIZE 100
#define OK 0
#define ERROR 1
#define OVERFLOW -1
typedef int Status;
typedef char QElemType;
//结构体
typedef struct
{
QElemType* base;
int front;
int rear;
}SqQueue;
//初始化
Status InitQueue(SqQueue& Q)
{
Q.base = new QElemType[MAXSIZE];
Q.front = Q.rear = 0;
return OK;
}
//入栈
Status EnQueue(SqQueue& Q, QElemType e)
{
if ((Q.rear + 1 + MAXSIZE) % MAXSIZE == Q.front)
{
return ERROR;
}
Q.base[Q.rear] = e;
Q.rear = (Q.rear + 1 + MAXSIZE) % MAXSIZE;
return OK;
}
//出栈
Status DeQueue(SqQueue& Q, QElemType& e)
{
if (Q.rear == Q.front)
return ERROR;
e = Q.base[Q.front];
Q.front = (Q.front + 1 + MAXSIZE) % MAXSIZE;
return OK;
}
//判断队列的长度
Status QueueLength(SqQueue& Q)
{
return (Q.rear - Q.front + MAXSIZE) % MAXSIZE;
}
//回文数判断函数
Status Inversion(char* str)
{
int len = strlen(str);
int i = 0;
SqQueue Q;
InitQueue(Q);
for (i = 0; i < len / 2; i++)
{
EnQueue(Q, str[i]);
}
int j = len % 2 == 0 ? len / 2 : len / 2 + 1;
QElemType e;
while (Q.front - Q.rear != 0)
{
if (j = len / 2 + 1)
{
DeQueue(Q, e);
if (e == str[++j])
return 0;
else
return 1;
}
else
{
DeQueue(Q, e);
if (e == str[j++])
return 0;
else
return 1;
}
}
}
//主函数
int main()
{
SqQueue Q;
char str[100] = { 0 };
printf("请输入一串数字:\n");
scanf("%s", &str);
if (Inversion(str) == 0)
{
printf("是回文数\n");
}
else
{
printf("不是回文数\n");
}
return 0;
}