ListNode* ReverseIteratively(ListNode* pHead)
{
ListNode* pNode = pHead;
ListNode* pReversedHead = NULL;
ListNode* pPrev = NULL;
while (pNode != NULL)
{
if (NULL == pNode->next)
{
pReversedHead = pNode;
}
pNode->next = pPrev;
pPrev = pNode;
pNode = pNode->next;
}
return pReversedHead;
}
单链表反转
最新推荐文章于 2024-08-31 15:48:32 发布