有头节点
参考: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;
}