数据结构 两个链表合并-python
来源:互联网 发布:miui8降级miui7数据 编辑:程序博客网 时间:2024/06/05 02:00
class Node(): def __init__(self, data=None, next=None): self.data = data self.next = nextn1 = Node(1, Node(3, Node(6, Node(7, Node(23, None)))))n2 = Node(4, Node(5, Node(8, Node(14, Node(34, None)))))def merge(n1,n2): if not n1 and n2: return n1 or n2 head = Node("begin",None) cur = head while n1 and n2: if n1.data < n2.data: cur.next = n1 cur = n1 n1 = n1.next else: cur.next =n2 cur = n2 n2 = n2.next if n1: cur.next = n2 else: cur.next =n1 return head.nextn = merge(n1,n2)while n : print(n.data) n = n.next
阅读全文
0 0
- 数据结构 两个链表合并-python
- 数据结构 合并两个链表
- 17合并两个有序链表PYTHON
- 【数据结构】单链表—合并两个排序链表 — 递归
- 数据结构与算法(二)合并两个有序链表
- 【数据结构练习】2.两个有序链表序列的合并
- 数据结构之两个线性表的合并
- 数据结构之两个有序表的合并
- 合并两个链表
- 合并两个链表
- 合并两个链表
- 合并两个链表
- 合并两个链表
- 合并两个链表
- 数据结构 链表合并
- python两个dictionary合并
- python两个文件合并
- Python -- 合并两个列表
- java类加载机制
- slice、splice和split各自的用法
- Android系统篇之—-Binder机制和远程服务调用机制分析
- Dos命令初阶--文件拷贝
- java、java Web 获取项目根路径
- 数据结构 两个链表合并-python
- Logistic分类函数
- bind(this)绑定this指向的对象、箭头函数和闭包
- GSM Hacking Part ① :使用SDR扫描嗅探GSM网络
- cxf发布webservice用到的所有jar包
- spring @component的作用
- Hive进阶之Hive的数据查询
- 深入理解java异常处理机制
- Html5与Css3元素和属性(一)