首页 > 其他 > 详细

Insertion Sort List

时间:2015-11-16 21:13:05      阅读:206      评论:0      收藏:0      [点我收藏+]

1. Title

Insertion Sort List

2. Http address

https://leetcode.com/problems/insertion-sort-list/

3. The question

Sort a linked list using insertion sort.

4. My code (AC)

 1  // Accepted
 2       public ListNode insertionSortListTwo(ListNode head) {
 3           ListNode dump = new ListNode(0);
 4           ListNode cur = head;
 5           ListNode tmp = null;
 6           ListNode pre = null;
 7           while( cur != null)
 8           {
 9               pre = dump;
10               while(pre.next != null && pre.next.val < cur.val)
11                       pre = pre.next;
12               tmp = pre.next;
13               pre.next = cur;
14               cur = cur.next;
15               pre.next.next = tmp;
16           }
17           return dump.next;
18       }

 

Insertion Sort List

原文:http://www.cnblogs.com/ordili/p/4970018.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!