leetcode 147. Insertion Sort List ----- java

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 node = head.next;
head.next = null;
ListNode start = head; while( no sdf sd sdfnull ){
ListNode nn = node.next;
ListNode first = start;
if( node.val < first.val){
node.next = first;
start = node;
}else{
while( first.next != null && first.next.val < node.val )
first = first.next;
node.next = first.next;
first.next = node; } node = nn; }
return start; }
}
上一篇:Django 博客单元测试:测试评论应用


下一篇:移动端a链接点击时取出背景色及边框