其他分享
首页 > 其他分享> > 链表翻转

链表翻转

作者:互联网

ListNode* ReverseList(ListNode* pHead)
{
if (pHead == NULL)
{
return NULL;
}

ListNode pHeadNew(0);
pHeadNew.next = pHead;

ListNode* curNode = pHead;
ListNode* nextNode = pHead->next;
while (nextNode != NULL)
{
curNode->next = nextNode->next;
nextNode->next = pHeadNew.next;
pHeadNew.next = nextNode;
nextNode = curNode->next;
}

return pHeadNew.next;
}

标签:ListNode,nextNode,next,链表,pHead,pHeadNew,curNode,翻转
来源: https://www.cnblogs.com/weiyouqing/p/14474021.html