有头节点
参考:https://blog.csdn.net/blioo/article/details/62050967
linkList reverse(linkList head){
linkList p,q,pr;
p = head->next;
q = NULL;
head->next = NULL;
while(p){
pr = p->next;
p->next = q;
q = p;
p = pr;
}
head->next = q;
return head;
}
无头节点
public ListNode ReverseList(ListNode head) {
ListNode p,q,pr;
p=head.next;
q=null;
head.next=null;
while(p!=null)
{
pr=p.next;
p.next=q;
q=p;
p=pr;
}
head.next=p;
return head;
}
本文深入探讨了链表逆序算法的实现细节,分别介绍了带头节点和不带头节点的链表逆序过程,通过具体的伪代码展示了如何通过迭代方式改变链表中节点的指向,从而达到逆序的效果。

1462

被折叠的 条评论
为什么被折叠?



