//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;
}
Insertion Sort List
最新推荐文章于 2022-04-09 13:42:00 发布