147. Insertion Sort List
来源:互联网 发布:公知什么意思 编辑:程序博客网 时间:2024/06/02 06:03
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); ListNode *cur = head; while (cur) { ListNode *tmp = cur->next; ListNode *prev = &dummy; while (prev->next && prev->next->val < cur->val) { prev = prev->next; } cur->next = prev->next; prev->next = cur; cur = tmp; } 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
- UVA 674 - Coin Change 完全背包求状态数
- (转)Webstorm常用快捷键
- R中ifelse、which、%in%的用法
- 顺序表应用1:多余元素删除之移位算法
- cardview的使用
- 147. Insertion Sort List
- hadoop分布式安装
- 编译openjdk1.7
- flex-wrap
- 顺序表应用2:多余元素删除之建表算法
- 第二章——深入了解超文本
- 享元模式(结构型)
- 高通 MSM8K bootloader 之二: SBL1
- JUnit4 简介