insertion-sort-list
来源:互联网 发布:免费视频软件 编辑:程序博客网 时间:2024/06/05 04:43
//Sort a linked list using insertion sort
//单链表的插入排序
/**
* Definition for singly-linked list.
* public class ListNode
*{
* int val;
* ListNode next;
* ListNode(int x) {
* val = x;
* next = null;
* }
* }
*/
public ListNode insertionSortList(ListNode head)
{
if(head == null || head.next == null)
{
return head;
}
ListNode _newHead = new ListNode(Integer.MIN_VALUE);
ListNode _node = head;
while(_node != null)
{
ListNode _p = _newHead;
//记录_node的下一个节点
ListNode _next = _node.next;
while(_p.next != null && _p.next.val <= _node.val)
{
_p = _p.next;
}
_node.next = _p.next;
_p.next = _node;
_node = _next;
}
return _newHead.next;
}
- Insertion Sort List | leetcode
- Leetcode: Insertion Sort List
- [LeetCode] Insertion Sort List
- Insertion Sort List
- Leetcode: Insertion Sort List
- [LeeCode] Insertion Sort List
- leetcode-Insertion Sort List
- [LeetCode]Insertion Sort List
- Insertion Sort List
- 【LeetCode】Insertion Sort List
- LeetCode | Insertion Sort List
- LeetCode - Insertion Sort List
- Insertion Sort List
- Insertion Sort List
- Insertion Sort List
- Insertion Sort List
- [LeetCode] Insertion Sort List
- list - insertion sort - AC
- Android 在Thread中弹出Toast
- 关于如何建立链接的标签使用
- html
- 关于C语言的复杂申明学习
- 关于函数指针在单片机上的应用
- insertion-sort-list
- 1129
- 不会用u盘winPE里的小工具,还好意思说自己是大神!
- Android-布局02
- 什么是闭包?闭包的工作原理、优缺点、使用场景和对页面的影响
- Python:操作dict时避免出现KeyError的几种方法
- [音之国度读存档]实现篇
- 在Linux(CentOS)上开启小度WIFI无线AP模式
- c++STL基础部分(一)