struct Node* RevertLink_Recursive(struct Node* pHead)
{
if (NULL == pHead)
return NULL;
if (NULL == pHead->pNext)
return pHead;
struct Node* pCur = pHead->pNext; // 暂存pHead->pNext
struct Node* pNewHead = RevertLink_Recursive(pHead->pNext); // 返回反转后的头结点
pCur->pNext = pHead; // 连上前面的结点
pHead->pNext = NULL; // 反转后的单向链表的末尾结点置为空
return pNewHead;
}
递归方法反转单向链表(C/C++)
最新推荐文章于 2025-03-23 19:59:13 发布