Discription:
Sort a linked list using insertion sort.
Solution:
ListNode* insertionSortList(ListNode* head) {
if (!head) return head;
ListNode *head1 = new ListNode(-1), *head2 = head->next;
head1->next = head;
while (head2){
head = head1;
while (head->next && head->next->val <= head2->val)
{
head = head->next;
}
ListNode *temp = head2->next;
head2->next = head->next;
head->next = head2;
head2 = temp;
}
return head1->next;
}