题目描述
If a list is central symmetry, it is called a central list. for example, 1->3->5->7->9->7->5->3->1 is a central list.
Give you a sequence of numbers, form a link list and then judge whether it is a central list.
Input, a sequence of numbers seperated by comma
Output, if it is a central list output Yes, other wise No
```c
#include <stdlib.h>
#include <stdio.h>
struct Node;
typedef struct Node *ptrtoNode;
typedef ptrtoNode position;
typedef ptrtoNode Head;
struct Node
{
char x;
position nextPre;
position nextPost;
};
int main()
{
Head head;
head = malloc(sizeof(struct Node));
head->nextPost = NULL;
head->nextPre = NULL;
position pLast = head;
char x;
while ((x = getchar()) != '\n')
{
if (x != ',')
{
position pnew = malloc(sizeof(struct Node));
pnew->x = x;
pLast->nextPost = pnew;
pnew->nextPre = pLast;
pnew->nextPost = NULL;
pLast = pnew;
}
}
position p1 = head->nextPost;
position p2 = pLast;
int flag = 1;
while (p1 != p2 && flag == 1)
{
if (p1->x != p2->x)
{
flag = 0;
}
p1 = p1->nextPost;
p2 = p2->nextPre;
}
if (flag == 1)
printf("Yes\n");
else
printf("No\n");
return 0;
}