#include<stdio.h>
#include<stdlib.h>
#define MAXCHAR 40
struct node
{
char data;
struct node *next;
};
int ishs(struct node *head,int n)
{
char stack[MAXCHAR/2];
struct node *p = head;
int top = 0;
while(top<n/2) //前半部分元素入栈
{
stack[top] = p->data;
top++;
p=p->next;
}
if(n%2==1) //n为奇数
p=p->next;
top--;
while(top>=0&&p!=NULL&&stack[top]==p->data) //边退栈边比较
{
top--;
p = p->next;
}
if(top==-1&&p==NULL) //栈空且链表比较完毕,是回文数
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余2页未读,立即下载