Insertion Sort List

来源:互联网 发布:安装php基础环境搭建 编辑:程序博客网 时间:2024/06/07 08:39
   //ref : http://www.cnblogs.com/springfor/p/3862468.html    public ListNode insertionSortList(ListNode head) {        if(head==null || head.next==null) return head;        ListNode t = new ListNode(0);      // t.next = head;        ListNode cur = head;         while(cur!=null){            ListNode pre = t;            ListNode next = cur.next;            while(pre.next!=null && pre.next.val < cur.val){                pre = pre.next;            }                        cur.next = pre.next;            pre.next = cur;            cur = next;                    // 这几步骤转换挺重要的                            }        return t.next;    }

0 0
原创粉丝点击