typedef struct Node
{
int data;
struct Node* next;
}node, *pLinkedList;
bool isHuiWen(pLinkedList head)
{
if (head == NULL || head->next == NULL)
return true;
pLinkedList right = head->next;//保存中间节点的下一个节点(若为偶数则为偏右的中间节点)
pLinkedList cur = head; //快指针
while (cur->next != NULL && cur->next->next != NULL)
{
right = right->next;
cur = cur->next->next;
}
//当链表总结点个数为奇数情况时:
if (cur->next != NULL && cur->next->next == NULL)
right = right->next;
//将链表右边的节点放入一个栈中
stack<pLinkedList>* s = new stack<pLinkedList>();
while (right != NULL)
{
s->push(right);
right = right->next;
}
//比较链表左右两边节点是否相等
while (!s->empty())
{
if (head->next->data != s->top()->data)
return false;
s->pop();
head = head->next;
}
return true;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有