//输入一个链表,反转链表后,输出新链表的表头。
ListNode* ReverseList(ListNode* pHead) {
if (pHead == NULL) return NULL;
ListNode* pre = NULL;
ListNode* cur = pHead; //保存当前节点,用于循环
ListNode* pnext = pHead->next;//保存当前节点下一个节点
while(cur != NULL)
{
pnext = cur->next;
cur->next = pre;
pre = cur;
cur = pnext;
}
return pre;
}
06-30
417
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-23
3759
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-15
448
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)