Insertion Sort List
2015-08-27 21:59
211 查看
Sort a linked list using insertion sort.
public ListNode insertionSortList(ListNode head) { if(head == null){ return head; } ListNode helper = new ListNode(0); ListNode cur = head; ListNode next = null; ListNode pre = helper; 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; pre = helper; cur = next; } return helper.next; }
相关文章推荐
- JavaFX中javafx.concurrent.Task类的使用
- iOS中的触摸事件(TouchView) - (代理响应) - (实现touch的按钮化)(target/action设计模式,代理设计模式)重点
- HDU 4612 Warm up
- QT快捷键
- 设计功能和界面测试用例
- 对梯度下降法的简单理解
- 我的第一个网页
- 轻松python文本专题-字符串开头或者结尾匹配
- 【APUE】Chapter11 Threads
- 轻松python文本专题-字符串开头或者结尾匹配
- SharePoint 2013 Power Pivot 配置与测试详细说明(图解)
- IT 架构和应用程序的端到端测试
- Iterator模式
- CopyOnWriteArraySet<E>和CopyOnWriteArrayList<E>
- 堆排序
- 1302 The Snail【模拟】
- 设计并实现一个散列表,使用链表(即链表)处理碰撞冲突
- js怎么判断文本框中全是空格
- ZooKeeper - O'Reilly Media ---- Zookeeper Internals (4)
- css3的新增属性transform