单链表反转

public static Node reverseLinklist(Node head){
        Node pre=null;  //pre引用(指针)指向null
        Node next=null;
        while (head!=null){
            next=head.next;  //next指针指向head.next指向的位置
            head.next=pre;  //head.next指针指向pre指向的位置
            pre=head;
            head=next;
        }
        return pre;  //返回head引用(指针)
    }

 

posted @ 2022-02-09 11:54  狂忍日记  阅读(50)  评论(0)    收藏  举报