public ListNode insertionSortList(ListNode head) {
if (head == null) {
return null;
}
// this is the new head, don't need to dummy.next = head;
ListNode dummy = new ListNode(-1);
// consider first half is sorted
// pick next one and insert it in there
while (head != null) {
ListNode node = dummy;// node before the insertion point
while (node.next != null && node.next.val < head.val) {
node = node.next;
}
ListNode tmp = head.next;
head.next = node.next;
node.next = head;
head = tmp;
}
return dummy.next;
}