Insertion Sort List Posted on 2018-10-03 Descriptionhttps://leetcode.com/problems/insertion-sort-list/description/ Solution123456789101112131415161718192021222324252627/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* insertionSortList(ListNode* head) { ListNode* fakeHead = new ListNode(0); fakeHead->next = NULL; ListNode* cur = head; while (cur != NULL) { ListNode* pre = fakeHead; int value = cur->val; while(pre->next != NULL && value > pre->next->val) pre = pre->next; ListNode* temp = cur->next; cur->next = pre->next; pre->next = cur; cur = temp; } return fakeHead->next; }};