[leetcode 147] Insertion Sort List
来源:互联网 发布:vb设置焦点 编辑:程序博客网 时间:2024/05/17 08:53
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 dummy(-1); dummy.next = head; ListNode *prev = &dummy; for (auto first = prev->next ; first; ) { ListNode *second = dummy.next; ListNode *pre_second = &dummy; for (; second != first; pre_second = second, second = second->next) { if (second->val > prev->next->val) { prev->next = prev->next->next; first->next = second; pre_second->next = first; first = prev->next; break; } } if (second == first) { prev = prev->next; first = prev->next; } } return dummy.next; }};
0 0
- LeetCode(147) Insertion Sort List
- LeetCode: Insertion Sort List [147]
- LeetCode 147 Insertion Sort List
- [leetcode 147] Insertion Sort List
- LeetCode 147 Insertion Sort List
- LeetCode 147 Insertion Sort List
- [leetcode 147]Insertion Sort List
- leetcode-147 Insertion Sort List
- [LeetCode 147]Insertion Sort List
- Leetcode[147]-Insertion Sort List
- Insertion Sort List - LeetCode 147
- leetcode[147]:Insertion Sort List
- LeetCode(147) Insertion Sort List
- leetcode 147: Insertion Sort List
- [Leetcode]#147 Insertion Sort List
- leetCode #147 Insertion Sort List
- LeetCode 147 Insertion Sort List
- LeetCode 147:Insertion Sort List
- SpringMVC学习系列(7) 之 格式化显示
- forward和redirect的区别
- datagenerator
- SpringMVC学习系列(8) 之 国际化
- js中让字符串中特定字符红色显示
- [leetcode 147] Insertion Sort List
- C++的多态与虚函数
- JVM系列四:生产环境参数实例及分析
- JAVA 线程同步
- MyEclipse 注册不成功解决之道
- python获取ALM数据
- JAVA方法的分类
- C语言中的输入输出格式
- JVM系列五:JVM监测&工具