判断字符串对称
#include <iostream>
using namespace std;
/*
*writer:yaojinhui
*/
using namespace std;
typedef struct Lnode {
char data;
struct Lnode* next;
}Lnode, *Linklist;
Linklist tail_insert(Linklist L) {//尾插法创建单链表
L = (Linklist)malloc(sizeof(Linklist));
L->next = NULL;
Lnode *p;
Lnode *r = L;
char x;
while (true) {
cin >> x;
if (x == 'q')break;
p = (Lnode*)malloc(sizeof(Lnode));
p->data = x;
r->next = p;
r = p;
}
r->next = NULL;
return L;
}
void print(Linklist L) {//打印链表
Lnode *p = L->next;
while (p)
{ x
cout << p->data << " ";
p = p->next;
}
}
void isduicheng(Linklist L, int n) {
char s[100];
Lnode *p = L->next;
int i = 0, j = 0;
for (i; i < n / 2; i++) {
s[i] = p->data;
p = p->next;
}
i--;
if (n % 2 == 1) p = p->next;
for (j = i; j >= 0; j--) {
if (p->data == s[j]) p = p->next;
else
{
cout << "不对称";
break;
}
}
if (j <0)cout << "对称";
}
int main() {
int n;
cout << "打算创建多少个节点?"<<endl;
cin >> n;
Linklist L=NULL;
cout << "输入字符串,q结束输入" << endl;
L=tail_insert(L);
print(L);
isduicheng(L, n);
}