标签:
首先,演示一个错误的reverList
1 class Solution { 2 public: 3 ListNode* reverse(ListNode* root) 4 { 5 if(NULL == root) 6 return NULL; 7 ListNode* pCur = root; 8 ListNode* pNext = root->next; 9 10 while(pNext) 11 { 12 pNext = pNext->next; 13 pCur->next->next = pCur; 14 pCur = pCur->next; 15 } 16 root->next = NULL; 17 return pCur; 18 } 19 20 };
(2)--------->(3)-------->(4)----------->(5)--------->NULL
首先pCur指向2,pNext指向3;
pNext=pNext->next; pNext指向4,
pCur->next->next = pCur,然后3--->4 的指针断了, 从此pCur就自己转圈了。。。
[LeetCode] Add Two Numbers(stored in List)
标签:
原文地址:http://www.cnblogs.com/diegodu/p/4246326.html