单链表翻转Java实现

来源:互联网 发布:淘宝网帽子女士鸭舌帽 编辑:程序博客网 时间:2024/04/28 12:33
    public static LinkNode reverseLinkList(LinkNode head){        if(head == null || head.next == null)            return null;        LinkNode pre = head;        LinkNode q = head.next;        head.next = null;        while(q != null){            LinkNode nxt = q.next;            q.next = pre;            pre = q;            q = nxt;        }        return pre;    }
class LinkNode{    public LinkNode(int val){        this.val = val;        this.next = null;    }    int val;    LinkNode next;}


0 0
原创粉丝点击