LeetCode 147. Insertion Sort List
来源:互联网 发布:南京行知中学地址 编辑:程序博客网 时间:2024/05/16 17:02
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(0); while (head != NULL) { ListNode *pre = &dummy; ListNode *cur = head; head = head->next; while ((pre->next != NULL) && (pre->next->val <= cur->val)) { pre = pre->next; } if (pre->next == NULL) { pre->next = cur; cur->next = NULL; } else { cur->next = pre->next; pre->next = cur; } } return dummy.next; }};
0 0
- LeetCode 147. Insertion Sort List
- [LeetCode]147.Insertion Sort List
- [leetcode] 147.Insertion Sort List
- 147. Insertion Sort List LeetCode
- 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
- [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 143. Reorder List
- Javascript扩展String.prototype实现格式金额、格式时间、字符串连接、计算长度、是否包含、日期计算等功能
- POJ1064 Cable master[二分]
- javascript词法结构
- oracle的number数据类型
- LeetCode 147. Insertion Sort List
- 第十六周 项目3-归并排序算法的改进
- wordpress实现文章阅读次数
- 数据结构(三) 单链表的排序 ----按插入方法排序(带头节点)
- JAVA基础知识--BigDecimal类
- Zend Framework 2 学习教程链接
- 学习CDN!
- LeetCode 148. Sort List
- LeetCode 160. Intersection of Two Linked Lists