Insertion Sort List -- leetcode
2017-04-26 20:57
316 查看
Sort a linked list using insertion sort.
/** * 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 fake(0); while (head) { ListNode *runner = &fake; while (runner->next && runner->next->val < head->val) runner = runner->next; ListNode *bak = head->next; head->next = runner->next; runner->next = head; head = bak; } return fake.next; } };
相关文章推荐
- [LeetCode]Insertion Sort List
- LeetCode(147) Insertion Sort List
- leetcode第一刷_Insertion Sort List
- [leetcode] Insertion Sort List
- Leetcode_Insertion Sort List
- Insertion Sort List 【leetcode】
- [leetcode]Insertion Sort List @ Python
- leetcode Insertion Sort List(*)
- 【LeetCode】Insertion Sort List
- LeetCode Insertion Sort List 最新题解
- leetcode - Insertion Sort List
- [leetcode] Insertion Sort List(python)
- leetcode---Insertion Sort List
- 59_leetcode_Insertion Sort List
- LeetCode——Insertion Sort List
- (leetcode)Insertion Sort List
- LeetCode Insertion Sort List
- LeetCode 147 Insertion Sort List(链表插入排序)
- [leetcode] Insertion Sort List
- leetcode147~Insertion Sort List