leetcode--Insertion Sort List
2015-06-19 18:30
344 查看
Sort a linked list using insertion sort.
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ public class Solution { public ListNode insertionSortList(ListNode head) { if(head==null) return null; ListNode p = new ListNode(Integer.MIN_VALUE); ListNode cur = head; ListNode t = p; while(cur!=null){ ListNode n = cur.next; t = p; while(t.next!=null&&t.next.val<cur.val){ t = t.next; } cur.next = t.next; t.next = cur; cur = n; } return p.next; } }
相关文章推荐
- Perl Learning 1 Scalar Data
- viewPager 指针实现关键代码
- 在浏览器中运行applet
- Thinkphp3.2.2多语言包实现
- 马上去行动马上去体验
- 数据降维--低秩恢复
- 滥用的单例模式
- js变量数组
- leecode(1)Two Sum
- Linux VGA驱动移植实验
- JS问题汇总
- LibLinear(SVM包)的MATLAB安装
- Java 文件上传 JQ 文件上传
- (转)dedecms插件开发简明教程
- 创建一个字符设备驱动
- PHP常用函数总结
- 林达华推荐的几本数学书
- 大海捞枕木:大数据处理平台的衍变
- Markdonw 小技巧
- 只要游戏没有结束,你就有成为神的可能