147. Insertion Sort List
来源:互联网 发布:centos web 编辑:程序博客网 时间:2024/04/19 06:26
Sort a linked list using insertion sort.
Solution1
public static ListNode insertionSortList(ListNode head) {if( head == null ){ return head; } ListNode dummy = new ListNode(0); //new starter of the sorted list ListNode cur = head; //the node will be inserted ListNode pre = dummy; //insert node between pre and pre.next ListNode next = null; //the next node will be inserted //not the end of input list while( cur != null ){ next = cur.next; //find the right place to insert while( pre.next != null && pre.next.val < cur.val ){ pre = pre.next; } //insert between pre and pre.next cur.next = pre.next; pre.next = cur; pre = dummy; cur = next; } 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
- Copss安装过程
- Git软件安装
- epoll_wait返回的描述符该怎么去取和用
- iOS 常常遇到的遇到的警告、错误,解决方法
- socket中套接字传递给其他进程的问题
- 147. Insertion Sort List
- 《HTML+CSS基础课程》学习笔记四
- 单片机蜂鸣器奏乐代码例子
- 《HTML+CSS基础课程》学习笔记五
- 【Poj 2451】Uyuw's Concert
- oracle 创建DBLink
- 12.11 编程练习
- 【BZOJ 1013】 [JSOI2008]球形空间产生器sphere|高斯消元
- 读MBA经历回顾(上)目的决定手段——北漂18年(48)