Sort a linked list using insertion sort.
class Solution {
public:
ListNode *insertionSortList(ListNode *head) {
if(!head || !head->next)return head;
ListNode dummyHead(0),*p;
dummyHead.next = insertionSortList(head->next);
p = &dummyHead;
while(p && p->next && head->val > p->next->val) {
p = p->next;
}
head->next = p->next;
p->next = head;
return dummyHead.next;
}
};