Insertion Sort List Time : Space : 12345678910111213141516171819202122232425262728293031323334353637/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ ListNode* reverse(ListNode* A) { ListNode* dummy = new ListNode(-1); while(A) { ListNode* nxt = A->next; A->next = dummy->next; dummy->next = A; A = nxt; } return dummy->next;}ListNode* Solution::insertionSortList(ListNode* A) { ListNode* dummy = new ListNode(INT_MAX); while(A) { ListNode* runner = dummy; ListNode* now = A; A = A->next; now->next = NULL; while(runner->next and runner->next->val > now->val) { runner = runner->next; } now->next = runner->next; runner->next = now; } return reverse(dummy->next);}