标签:scribe nod next while reverse subject 反转链表 targe ==
/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};*/
class Solution {
public:
ListNode* ReverseList(ListNode* pHead) {
if(NULL==pHead || NULL==pHead->next) return pHead;
ListNode *p,*q,*r;
p=pHead;
q=pHead->next;
pHead->next=NULL;
while(q) {
r=q->next;
q->next=p;
p=q;
q=r;
}
pHead=p;
return pHead;
}
};
下面这思路居然 溢出,超时!!!
ActList* ReverseList3(ActList* head)
{
ActList* p;
ActList* q;
p=head->next;
while(p->next!=NULL){
q=p->next;
p->next=q->next;
q->next=head->next;
head->next=q;
}
p->next=head;//相当于成环
head=p->next->next;//新head变为原head的next
p->next->next=NULL;//断掉环
return head;
}
http://blog.csdn.net/feliciafay/article/details/6841115
http://blog.csdn.net/hyqsong/article/details/49429859
http://www.cnblogs.com/byrhuangqiang/p/4311336.html
标签:scribe nod next while reverse subject 反转链表 targe ==
原文地址:http://www.cnblogs.com/dd2hm/p/7291247.html