leetcode:Insertion Sort List
来源:互联网 发布:windows测试udp端口 编辑:程序博客网 时间:2024/06/05 20:03
单链表的插入排序
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class Solution { public ListNode insertionSortList(ListNode head) { if (head != null && head.next != null) { ListNode otherHead = null; otherHead = head.next; head.next = null; while (otherHead != null) { ListNode node = otherHead; otherHead = otherHead.next; node.next = null; ListNode t = head; ListNode pre = head; while(t != null){ if(t.val > node.val){ break; } pre = t; t = t.next; } if(t == pre){ node.next = t; head = node; } else{ pre.next = node; node.next = t; } } } return head; }}
0 0
- Insertion Sort List | leetcode
- Leetcode: Insertion Sort List
- [LeetCode] Insertion Sort List
- Leetcode: Insertion Sort List
- leetcode-Insertion Sort List
- [LeetCode]Insertion Sort List
- 【LeetCode】Insertion Sort List
- LeetCode | Insertion Sort List
- LeetCode - Insertion Sort List
- [LeetCode] Insertion Sort List
- Insertion Sort List (LeetCode)
- [LeetCode] Insertion Sort List
- [LeetCode]Insertion Sort List
- leetcode Insertion Sort List
- Insertion Sort List -- LeetCode
- Insertion Sort List (LeetCode)
- LeetCode Insertion Sort List
- leetcode Insertion Sort List
- 超级博客 c++编程学习注意点 2011-3-31
- lsof(list open files)(未完)
- 实现DataGridView和DevExpress.GridControl表头全选功能
- Windows Azure Web Role 的 IIS 重置
- 常用js(包含省市级联、html多样格式)
- leetcode:Insertion Sort List
- 程序报错找不到原因高手进来看看
- C++日志系统log4cxx使用总结
- 超级博客 C++学习
- jsp对应list做非空判断
- binary search tree
- Unity3D移动端内存优化(NGUI方面)
- 自然语言处理(NLP)网上资源整理3
- thinkphp 如何给控制器传值,实现按钮删除数据库信息