insertion-sort-list使用插入排序对链表进行排序
代码:
package com.niuke.p5; public class Solution { public ListNode insertionSortList(ListNode head) { ListNode dumpy = new ListNode(Integer.MIN_VALUE); ListNode cur = head; ListNode pre = dumpy; while(cur != null) { ListNode next = cur.next; pre = dumpy; while(pre.next != null && pre.next.val < cur.val) { pre = pre.next; } cur.next = pre.next; pre.next = cur; cur = next; } return dumpy.next; } }
心再坚强也不要独自飞翔