单链表的反转?
思路:
public static void reverseList(HeroNode head){
if (head.next==null||head.next.next==null){
return ;
}
HeroNode cur =head.next;
HeroNode next=null;
HeroNode reverseHead=new HeroNode(0,"","");
while (cur!=null){
next=cur.next;
cur.next=reverseHead.next;
reverseHead.next=cur;
cur=next;
}
head.next=reverseHead.next;
}
思想就是头插法,如图:
欢迎大家在评论区讨论~