LeetCode Insertion Sort List
2016-03-02 10:51
330 查看
/** * 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 = new ListNode(-1);//dummy node; ListNode* cur = head;//node to be inserted ListNode* pre=dummy;//node will be inserted between pre and pre->next; ListNode* next ;//cur->next while(cur!=NULL){ next=cur->next; while(pre->next!=NULL&&(pre->next->val<=cur->val)) pre=pre->next; cur->next = pre->next; pre->next = cur; cur=next; pre=dummy; } return dummy->next; } };
相关文章推荐
- windows genymotion 安装报错和idea启动genymotion报错
- 【实例解析】某水泥企业应用商业智能提升管理效率
- 添加删除区别
- 微信公众号 菜单
- 详解SQLServer 存储过程
- ZooKeeper程序员指南(转)
- 套接字
- 安装Genymotion出现的错误
- c++的几种典型数据类型
- iOS UIButton 设置图片文字垂直排列
- tsiLtroSnoitresnI.147
- 67.Which two statements are true regarding the ORDER BY clause? (Choose two.)
- php 学习笔记 —— 基础语法 (一)
- 常见数据结构复杂度
- (转)WebApi自动生成在线文档Swashbuckle
- pymysql
- RGB颜色查询对照表
- 卡马克:用C++进行函数式编程
- Shell编程中Shift的用法
- 文本挖掘之降维之特征抽取之主成分分析(PCA)