数据结构队列检测回文数有问题!
程序代码:#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
typedef struct Qnode
{
char date;
struct Qnode *next;
}QNode;
QNode *creat()
{
QNode *head=NULL,*p=NULL,*s=NULL;
char date;
head=(QNode *)malloc(sizeof(QNode));
if(head==NULL)
{
printf("建立链表失败\n");
return 0;
}
head->next=NULL;
p=head;
printf("请输入一个数字字符串\n");
date=getchar();
while(date!='\n')
{
s=(QNode *)malloc(sizeof(QNode));
if(s==NULL)
{
printf("新结点创建失败\n");
return NULL;
}
else /*if(Name[0]!='0')*/
{
s->date=date;
s->next=NULL;
p->next=s;
p=s;
}
date=getchar();
}
return head;
}
int main()
{
int n=1,i,flag=1;
QNode *a=creat();
QNode *front=a,*rear=a;
if((a->date)/*!=NULL*/)
{
n++;
rear=a;
a=a->next;
}
for(i=0;i<(n/2);i++)
{
if((front->date)==(rear->date))
{
front=front->next;rear=rear->next;
}
else
{
flag=0;
break;
}
}
if(flag)
printf("该数组是回文数\n");
else
printf("该数组不是回文数\n");
system("peuse");
return 0;
}
为什么检测不了?哪里有问题?都显示的是回文数






