147. Insertion Sort List
来源:互联网 发布:ubuntu配置ip 编辑:程序博客网 时间:2024/04/24 10:42
题目:
Sort a linked list using insertion sort.
对链表进行插入排序。
public ListNode insertionSortList(ListNode head) { if(head == null || head.next == null) return head;ListNode newnode =new ListNode(0);newnode.next = head;ListNode p = head.next;head.next=null;ListNode cur;while (p!=null){cur =p;p=p.next;ListNode node=newnode.next; //已排好序头节点ListNode pre = newnode;while(true){if(cur.val<node.val) //将cur节点插入到node前面{pre.next = cur;cur.next= node;break;}else{ //node后移pre = node;node=node.next;}if(node ==null) //将cur添加到已排好序最后{pre.next=cur;cur.next=null;break;}}}return newnode.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
- Python中的引用,copy和deepcopy的区别
- linux 正常关机
- 利用C++11新特性重构自定义Button
- CRegKey::open调用失败
- nmealib代码分析
- 147. Insertion Sort List
- VIM SourceInsight 等嵌入式开发编辑器使用心得
- Android_自定义url路径web端打开App
- 小话HTTP Authentication
- 字符串hash,康托展开总结
- POJ-Palindrome(马拉车模板题)
- 聊天界面关键代码实现
- HDU 1896
- 小菜鸟的C++游戏编程学习日记(一)