Insertion Sort List
来源:互联网 发布:经济学推荐书籍 知乎 编辑:程序博客网 时间:2024/06/16 09:28
------QUESTION------
Sort a linked list using insertion sort.
------SOLUTION------
class Solution {public: ListNode *insertionSortList(ListNode *head) { if(!head || !head->next) return head; ListNode *tail =head->next; head->next = NULL; ListNode *current; ListNode *tmp; while(tail){ if(tail->val < head->val){ tmp = tail->next; tail->next = head; head = tail; tail = tmp; continue; } current = head; while(current->next && tail->val >= current->next-> val) current = current->next; tmp = tail->next; tail->next = current->next; current->next = tail; tail = tmp; } return head; }};
0 0
- Insertion Sort List | leetcode
- Leetcode: Insertion Sort List
- [LeetCode] Insertion Sort List
- Insertion Sort List
- Leetcode: Insertion Sort List
- [LeeCode] Insertion Sort List
- leetcode-Insertion Sort List
- [LeetCode]Insertion Sort List
- Insertion Sort List
- 【LeetCode】Insertion Sort List
- LeetCode | Insertion Sort List
- LeetCode - Insertion Sort List
- Insertion Sort List
- Insertion Sort List
- Insertion Sort List
- Insertion Sort List
- [LeetCode] Insertion Sort List
- list - insertion sort - AC
- 设计模式 - 适配器模式 C++
- Reorder List
- 新手如何学习C#、ASP.NET
- LRU Cache
- GeoGeo大数据集
- Insertion Sort List
- Sort List
- LeetCode: Remove Duplicates from Sorted Array
- Max Points on a Line
- GeoGeo Master-Slave窗口事件
- 单例与static函数
- ARMHF versus ARMEL
- Catalogue of leetcode
- Android Sensor 移植