LeetCode之Insertion Sort List
2015-08-01 10:23
459 查看
/** * 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) { if(head == nullptr || head->next == nullptr) return head; ListNode node(-1); node.next = head; ListNode *p(head->next), *q; head->next = nullptr; while(p){ q = &node; while(q->next && q->next->val < p->val) q = q->next; ListNode *tmp = p; p = p->next; tmp->next = q->next; q->next = tmp; } return node.next; } };
相关文章推荐
- OSCache分布式集群配置
- 方法:initWithNibName
- 消息中间件
- 2015ACM多校对抗赛第四场 hdu 5335
- tpcc-mysql安装、使用、结果解读
- hihoCoder 1049 后序遍历
- P-Called-Party-ID 头域的应用说明
- 1023. Have Fun with Numbers (20)
- Unity-Attribute
- Github免费账户使用”私有库“
- css 7.30
- 自定义ImageView
- 集合
- 分解质因数
- All in All - poj 1936 (子串)
- STM32中GPIO口的8种模式
- 新的公司,新的技术
- 值语义与对象语义
- CABasicAnimation animationWithKeyPath
- 万丈高楼从0开始。