Insertion Sort List
来源:互联网 发布:ubuntu命令行复制文件 编辑:程序博客网 时间:2024/06/01 07:48
Sort a linked list using insertion sort
链表的插入排序
struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; class Solution {public:ListNode *insertionSortList(ListNode *head) { if(head == NULL || head->next == NULL)return head;ListNode *cur = head->next;head->next = NULL;while(cur != NULL){ListNode *next = cur->next;if(cur->val < head->val){cur->next=head;head = cur;}else{ListNode * pre = head, *post = head->next;while(post && cur->val > post->val ){pre = post;post = post->next;}pre->next = cur;cur->next = post;}cur = next;} return head;}};刚开始老是报错,结果发现我把判空操作跟val值比较大小的顺序搞颠倒了...不确保非空怎么能比较值了...又脑残了一把
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
- linux下的 jmap命令
- 使用 JCaptcha 开发图形和声音验证码
- .Net解析JSON字符串
- unix c-金额类型转成英文大写
- 推荐几个好用且免费的SQLite图形化管理工具
- Insertion Sort List
- Axis2 SSL
- 通过velocity模板和Hibernate sql-query的实现动态hql
- 使用MessageFormat处理包含占位符的字符串
- 浮点型(float和double)
- PHP调用汇率源代码
- 升级到 Xcode5.1, iOS 7.1 之后,zxing 编译出错
- “Exception in thread "main" java.lang.OutOfMemoryError: Java heap space ”
- eclipse中使用git