LeetCode: Insertion Sort List
2015-05-26 10:44
239 查看
Title:
Sort a linked list using insertion sort.
Sort a linked list using insertion sort.
class Solution { public: ListNode *insertionSortList(ListNode *head) { ListNode* sortedHead = new ListNode(0); while (head){ ListNode* cur = sortedHead; ListNode* tmp = head->next; while (cur->next != NULL && cur->next->val < head->val){ cur = cur->next; } head->next = cur->next; cur->next = head; head = tmp; } return sortedHead->next; } };
相关文章推荐
- leetcode_Sort a linked list using insertion sort.
- LeetCode Insertion Sort List
- LeetCode: Insertion Sort List(外加对单链表类题目的思考总结)
- LeetCode Insertion Sort List
- 【leetcode】 Insertion_Sort_List
- LeetCode Insertion Sort List
- [LeetCode]Insertion Sort List
- 【leetcode】insertion-sort-list
- leetcode之Insertion Sort List
- [leetcode147]insertion sort list
- LeetCode_Insertion Sort List
- [Leetcode][python]Insertion Sort List
- leetcode--Insertion Sort List
- leetcode--Insertion Sort List
- LeetCode---Insertion Sort List
- LeetCode Insertion Sort List
- LeetCode(2):insertion-sort-list
- The Solution to LeetCode 147 Insertion Sort List
- Leetcode Insertion Sort List 解题报告
- [LeetCode]Insertion Sort List