双链表反转

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

 

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