标签:
带头结点的链表结点定义如下:
1 struct ListNode 2 { 3 int value; 4 ListNode *next; 5 };
代码如下:
1 ListNode* Reverse(ListNode *pHead) 2 { 3 ListNode *pReverse = NULL; 4 ListNode *pNode = pHead; 5 ListNode *pPre = NULL; 6 7 while(pNode){ 8 ListNode *pNext = pNode->next; 9 10 if(pNext==NULL) 11 pReverse = pNode; 12 13 pNode->next = pPre; 14 15 pPre = pNode; 16 pNode = pNext; 17 } 18 return pReverse; 19 }
标签:
原文地址:http://www.cnblogs.com/balingybj/p/4507819.html