数据结构 两个链表合并-python
2017-06-27 17:28
471 查看
class Node(): def __init__(self, data=None, next=None): self.data = data self.next = next n1 = 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.next n = merge(n1,n2) while n : print(n.data) n = n.next
4000
相关文章推荐
- 17合并两个有序链表PYTHON
- c语言数据结构中两个有序链表合并为一个新链表
- python 合并两个排序的链表
- 【MOOC—数据结构习题】两个有序链表序列的合并
- PAT数据结构_02-线性结构1 两个有序链表序列的合并 (15分)
- [LeetCode] 21. Merge Two Sorted Lists 合并两个有序链表 @python
- 数据结构 合并两个链表
- 剑指offer之合并两个排序的链表(Python)
- python 合并两个排序的链表
- 2-11. 两个有序链表序列的合并(15):链表数据结构基础练习
- 数据结构-合并两个排序的链表
- LeetCode--Merge Two Sorted Lists(合并两个有序链表)Python
- 02-线性结构1 两个有序链表序列的合并——中国大学MOOC-陈越、何钦铭-数据结构-2017秋
- 数据结构 - 有两个链表,第一个升序,第二个降序,合并为一个升序链表(C++)
- 合并两个排序的链表[剑指offer]之python实现
- 数据结构之将两个递增的有序链表合并为一个递增的有序链表
- 数据结构 02-线性结构1 两个有序链表序列的合并
- 数据结构_中国大学MOOC(慕课)——两个有序链表序列的合并问题
- [数据结构]02-线性结构1 两个有序链表序列的合并
- python实现合并两个排序链表