刚接触C有道题不会,请前辈帮忙了

来源:百度知道 编辑:UC知道 时间:2024/06/05 19:31:15
判定字符单链表所表示的字符串是否是中心对称的。

用两个指针从两头一一比较相应的字符即可。

/*在win-tc中运行成功,以前做的判断回文的,比如abcddcba这样的,
应该符合你要求的,先看看*/
typedef struct Node
{
char data;
struct Node *next;
}Node,*LinkStack;
#define NULL 0
#include <string.h>
int InitStack();
void main()
{
InitStack() ? printf("Yes!\n") :printf("No!\n");
getch();
}
int InitStack()
{
int i, j = 0;
char *p;
LinkStack top;
Node *r, *s, *temp;
top = (Node *)malloc(sizeof(Node));
if(top == NULL)
{
printf("overflow!\n");
exit(0);
}
top -> next = NULL;
s = top;
printf("please input the strint:\n");
gets(p);
for(i = 0; i < strlen(p); i++)
{
r = (LinkStack)malloc(sizeof(Node));
r -> data = p[j++];
r -> next = s -> next;
s -> next = r;
}
j = 0;

for(i = strlen(p) - 1;