合并两个有序的单链表
来源:互联网 发布:淘宝店铺被扣48分 编辑:程序博客网 时间:2024/06/08 17:58
/** * Created by lxw, liwei4939@126.com on 2017/10/27. * 合并两个有序的单链表 */public class MergeSortedList { public class Node{ public int value; public Node next; public Node(int data){ this.value = data; } } public Node merge(Node head1, Node head2){ if(head1 == null || head2 == null) return head1 != null ? head1 : head2; Node head = head1.value < head2.value ? head1 : head2; Node cur1 = head == head1 ? head1 : head2; Node cur2 = head == head1 ? head2 : head1; Node pre = null; Node next = null; while (cur1 != null && cur2 != null){ if(cur1.value <= cur2.value){ pre = cur1; cur1 = cur1.next; } else { next = cur2.next; pre.next = cur2; cur2.next = cur1; pre = cur2; cur2 = next; } } pre.next = cur1 == null ? cur2 : cur1; return head; }}
阅读全文
0 0
- 两个有序单链表的合并&两个有序数组的合并
- 两个有序单链表的合并
- 合并两个有序的单链表
- 合并两个有序的单链表
- 合并两个有序的单链表
- 合并两个有序的单链表
- 合并两个有序的单链表
- 合并两个有序的单链表
- 合并两个有序的单链表
- 合并两个有序的单链表
- 合并两个有序单链表
- 合并两个有序单链表
- 合并两个有序单链表
- 两个有序单链表合并
- 合并两个有序单链表
- 合并两个有序单链表
- 合并两个有序单链表
- 合并两个有序单链表
- JAVA基础知识
- 剑指offer 跳台阶
- 10道典型的JavaScript面试题+5道JavaScript基础面试题
- 循环遍历总结(for/foreach/forin/forof/map/some/filter)
- 后台界面实时获取用户输入内容,springMVC+Ajax实现(源码)
- 合并两个有序的单链表
- 记录
- HDU P2586 How far away ?
- web开发|如何选择合适的webui框架
- memblock add memblock region流程
- MySQL Server 安装失败 The action 'Install' for product 'MySQL Server 5.7.20' failed.
- Python基础入门之List和Tuple类型一
- 用友T3-财务通百万用户纪念版V10.6破解
- 转载 解密蓝牙mesh系列 | 第八篇【蓝牙mesh网络强制使能安全性】【蓝牙mesh网络安全性的基本概念】【安全分级考量与安全密钥】【区域隔离】【节点移除、密钥刷新与垃圾桶攻击】【隐私】【中继攻击】