147. Insertion Sort List
来源:互联网 发布:幼儿教育软件哪个好 编辑:程序博客网 时间:2024/03/29 10:12
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(INT_MIN);while (head){ListNode* newHead = &dummy;while (newHead->next && head->val > newHead->next->val){//主要需要pre,所以这里是newHead->nextnewHead = newHead->next;}ListNode* next = head->next;ListNode* newNext = newHead->next;newHead->next = head;head->next = newNext;head = next;}return dummy.next;}};
0 0
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 147. Insertion Sort List
- 寻找第二小元素
- 一种 基于改进K_medoids的 句子文本聚类方法
- Toast统一管理类
- 每日一记-Maven使用简单小结
- MAC泛洪攻击和防御
- 147. Insertion Sort List
- POJ 1251 Jungle Roads 【最小生成树】
- HDU 2112 HDU Today【最短路+map容器,spfa算法+Dijkstra算法】
- 下载状态
- android实现自动更新
- javascript 之DOM篇
- PHP之MVC学习
- 用户输入非法内容时的震动与动画提示
- Jsoup