void Reverse(struct ListNode* p)
{
assert(p!=NULL);
if(p==NULL)
{
return;
}
struct ListNode* r=p->next;
p->next=NULL;
struct ListNode* s;
while(r!=NULL)
{
s=r->next;
r->next=p->next;
p->next=r;
r=s;
}
}
bool isPalindrome(struct ListNode* head)
{
assert(head!=NULL);
if(head==NULL)
{
return false;
}
struct ListNode* p=head->next;
struct ListNode* q=head->next;
while(q!=NULL&&q->next!=NULL)
{
p=p->next;
q=q->next->next;
}
struct ListNode* r;
for(r=head;r->next!=p;r=r->next)
{
;
}
Reverse(r);
struct ListNode* s=r->next;
while(head!=r->next&&s!=NULL)
{
if(head->val==s->val)
{
head=head->next;
s=s->next;
}
else
{
return false;
}
}
return true;
}