ListNode *insertionSortList(ListNode *head) {
if (!head) return head;
ListNode dummy(numeric_limits<int>::min());
while(head) {
ListNode *p = &dummy;
while(p->next && p->next->val <= head->val)
p = p->next;
ListNode *headNext = head->next;
head->next = p->next;
p->next = head;
head = headNext;
}
return dummy.next;
}
Online Judge Solutions
- Google (1)
- LeetCode Solutions (32)
- LintCode Solutions (68)
- Marked (38)
- Misc. (8)
Sunday, November 2, 2014
Insertion Sort List
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment