struct ListNode { int m_nKey; ListNode* next; } ListNode* reverseList(ListNode* pHead) { ListNode* pReversedHead = nullptr; ListNode* pNode = pHead; ListNode* pPrev = nullptr; while(pNode != nullptr){ ListNode* pNext = pNode->next; if(pNext == nullptr) pReversedHead = pNode; pNode->next = pPrev; pPrev = pNode; pNode = pNext; } return pReversedHead; } //备注:递归实现方式待完善?
原文地址:https://www.cnblogs.com/hujianglang/p/11421013.html
时间: 2024-10-08 20:11:46