码迷,mamicode.com
首页 > 其他好文 > 详细

*Insertion Sort List

时间:2015-12-21 07:04:28      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:

 

 

 

 

 

Sort a linked list using insertion sort.

 1 public class Solution {
 2     public ListNode insertionSortList(ListNode head) {
 3         ListNode dummy = new ListNode(0);
 4 
 5         while (head != null) {
 6             ListNode node = dummy;
 7             while (node.next != null && node.next.val < head.val) {
 8                 node = node.next;
 9             }
10             ListNode temp = head.next;
11             head.next = node.next;
12             node.next = head;
13             head = temp;
14         }
15 
16         return dummy.next;
17     }
18 }

 

*Insertion Sort List

标签:

原文地址:http://www.cnblogs.com/hygeia/p/5062374.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!