ListNode* ReverseList(ListNode* pHead)
{
ListNode* newList = NULL;
ListNode* cur = pHead;
ListNode* pre = NULL;
while (cur != NULL)
{
ListNode* next = cur->pNext;
if (next == NULL)
{
newList = cur;//这里需要注意临界点的判断
}
cur->pNext = pre;
pre = cur;
cur = next;
}
return newList;
}
反转链表
最新推荐文章于 2022-10-18 10:09:05 发布