https://leetcode-cn.com/problems/insertion-sort-list/
/**
* 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 *dummy = new ListNode(-1), *cur = dummy;//dummy新的的链表的头
while(head) {
ListNode *t = head->next;//暂时存储一下head,之后需要
cur = dummy;
while(cur->next && cur->next->val <= head->val) {
cur = cur->next;
}
head->next = cur->next;//将当前的head节点加进来
cur->next = head;
head = t;
}
return dummy->next;
}
};