leetcode---Insertion Sort List
2016-10-14 21:16
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) { if(head == NULL) return NULL; ListNode *start = new ListNode(0); ListNode *cur = head; while(cur) { ListNode *pre = start; while(pre->next && cur->val > pre->next->val) { pre = pre->next; } ListNode *next = cur->next; cur->next = pre->next; pre->next = cur; cur = next; } return start->next; } };
相关文章推荐
- The Solution to LeetCode 147 Insertion Sort List
- leetcode-Insertion Sort List
- 【Leetcode】Insertion Sort List (Sorting)
- 【LeetCode】Insertion Sort List 解题报告
- Insertion Sort List - LeetCode 147
- [LeetCode] Insertion Sort List
- Leetcode: Insertion Sort List
- leetcode-Insertion Sort List
- Leetcode---Insertion Sort List
- [LeetCode-Algorithms-147] "Insertion Sort List" (2017.12.21-WEEK16)
- LeetCode之Insertion Sort List
- Insertion Sort List -- LeetCode
- LeetCode 147 Insertion Sort List
- [Leetcode]Insertion Sort List
- leetcode Insertion Sort List
- LeetCode:Insertion Sort List
- leetcode insertion-sort-list
- LeetCode(147) Insertion Sort List
- LeetCode(147) Insertion Sort List
- leetcode 之 Insertion Sort List