标签:
1 /* 2 struct ListNode { 3 int val; 4 struct ListNode *next; 5 ListNode(int x) : 6 val(x), next(NULL) { 7 } 8 };*/ 9 class Solution { 10 public: 11 ListNode* ReverseList(ListNode* pHead) { 12 if(pHead==NULL||pHead->next==NULL) 13 return pHead; 14 ListNode* p=pHead; 15 ListNode* q=p->next ; 16 ListNode* s; 17 18 while(q!=NULL) 19 { 20 s=q->next; 21 q->next=p; 22 p=q; 23 q=s; 24 } 25 pHead->next=NULL; 26 return p; 27 28 } 29 };
标签:
原文地址:http://www.cnblogs.com/cancangood/p/4937064.html