资源描述
源代码:
#include<stdio.h>
#include<malloc.h>
#define null 0
#define max 50
typedef struct sn{
char data;
struct sn *next;
}node;
int ishw(node *head,int n){
char stack[max];
int top=0;
node *p;
p=head->next;
while(top<n/2)
{
stack[top]=p->data;
top++;
p=p->next;
}
top--;
if(n%2==1) p=p->next;
while(top>=0)
{
if(stack[top]!=p->data) return 0;
top--;
p=p->next;
}
return 1;
}
int push(node *head,char *s)
{ int i;
node *p,*q;
p=head;
for(i=0;s[i]!='@';i++)
{ q=(node *)malloc(sizeof(node));
q->data=s[i];
q->next=null;
p->next=q;
p=q;
}
return(i);
}
void main()
{ char s[max];
node *head;
int i;
printf("Please input a data(max size: %d):",max);
scanf("%s",s);
head=(node *)malloc(sizeof(node));
i=push(head,s);
if(ishw(head,i))
printf("It is a huiwenshu.\n");
else
printf("It is not a huiwenshu.\n");
}
展开阅读全文