struct Node
{
int value;
Node *next;
};
//head为原始链表的头节点,p初始值为head,newHead用来存储逆转后的头节点
void reverse(Node *head,Node *p, Node* &newHead)
{
if (NULL == head)
{
newHead = NULL;
return;
}
if (NULL == p->next)
{
newHead = p;
return;
}
else
{
reverse(head, p->next, newHead);
p->next->next = p;
}
if (p == head)
{
p->next = NULL;
}
}
单向链表逆转(递归)
最新推荐文章于 2024-08-14 10:12:09 发布