笨办法学Python3续 Learn more python3 in hard way ex16 merge sort 归并排序(暂完!!!)

我去找了个视频
https://www.bilibili.com/video/av17888875?from=search&seid=15493090710265132375
理论上讲是:把这个数列切成一块块不可分割的 再比大小连接在一起 放在一个result里
其实这个代码是很巧妙的 巧妙在于**

递归

**
zed这个实验是基于双向链表。且数字是随机
我调试了数量(10个随机数)和输出(增加输出)
直接放源码= -= GitHub吧

https://github.com/theguyisnoone/impthw/tree/master/ex16
运行代码:

----
[10,8,None] [8,8,10] [8,None,8] [0,4,8] [4,10,None] [10,None,4] [0,3,10] [3,6,None] [6,7,3] [7,None,6]
None
>>>mid:5
>>>mid:2
>>>mid:1
merged_left[10,None,None],merged_right[8,None,None]
>>> [10,None,None] [8,None,None]
>>> [10,None,None] None
result[8,10,None]
>>>mid:1
>>>mid:1
merged_left[0,None,None],merged_right[4,None,None]
>>> [0,None,None] [4,None,None]
>>> None [4,None,None]
result[0,4,None]
merged_left[8,None,None],merged_right[0,4,None]
>>> [8,None,None] [0,4,None]
>>> [8,None,None] [4,None,None]
>>> [8,None,None] None
result[4,8,None]
result[0,4,None]
merged_left[8,10,None],merged_right[0,4,None]
>>> [8,10,None] [0,4,None]
>>> [8,10,None] [4,8,None]
>>> [8,10,None] [8,None,4]
>>> [10,None,8] [8,None,4]
>>> [10,None,8] None
result[8,10,4]
result[8,8,None]
result[4,8,None]
result[0,4,None]
>>>mid:2
>>>mid:1
merged_left[10,None,None],merged_right[0,None,None]
>>> [10,None,None] [0,None,None]
>>> [10,None,None] None
result[0,10,None]
>>>mid:1
>>>mid:1
merged_left[6,None,None],merged_right[7,None,None]
>>> [6,None,None] [7,None,None]
>>> None [7,None,None]
result[6,7,None]
merged_left[3,None,None],merged_right[6,7,None]
>>> [3,None,None] [6,7,None]
>>> None [6,7,None]
result[3,6,None]
merged_left[0,10,None],merged_right[3,6,None]
>>> [0,10,None] [3,6,None]
>>> [10,None,None] [3,6,None]
>>> [10,None,None] [6,7,3]
>>> [10,None,None] [7,None,6]
>>> [10,None,None] None
result[7,10,6]
result[6,7,3]
result[3,6,None]
result[0,3,None]
merged_left[0,4,None],merged_right[0,3,None]
>>> [0,4,None] [0,3,None]
>>> [4,8,None] [0,3,None]
>>> [4,8,None] [3,6,None]
>>> [4,8,None] [6,7,3]
>>> [8,8,4] [6,7,3]
>>> [8,8,4] [7,10,6]
>>> [8,8,4] [10,None,7]
>>> [8,10,8] [10,None,7]
>>> [10,None,8] [10,None,7]
>>> None [10,None,7]
result[10,10,8]
result[8,10,8]
result[8,8,4]
result[7,8,6]
result[6,7,3]
result[4,6,None]
result[3,4,None]
result[0,3,None]
result[0,None,None]
----
[0,None,None] [0,3,None] [3,4,None] [4,6,3] [6,7,4] [7,8,6] [8,8,7] [8,10,8] [10,10,8] [10,None,10]
None
.

我没有完全搞懂 但是 这个输出应该明显点
这个归并排序太负杂了 很多递归 还有个不知所谓的类 有所谓的确定头和尾 调用merge_node 去了
= -= 我的脑子很凌乱 看运行的时候看第一个value就行了
双向链表

l give up!!=- =

后我又回来了 思想还是要捋一捋
讲的内容是差不多的 和别人写的
在这里插入图片描述
不断划分的过程
不断调用至不可分割
在这里插入图片描述
我们把东西都放在result里
在这里插入图片描述

拆开来是拆成两个有序序列(视频中用的是切片)
然后我们就不断的递归 递归到能直接返回start的值
执行下一句代码 在调用连接 得到一个result
在回到递归中 得到另外一个result
再连接成一个新的result

递归========》视频讲的不错

突然想到=- = atom有没有打断点的
这好像打断点能解决的= -=

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python进阶书籍,Transform Your Ideas into High-Quality Python Code! Zed Shaw has perfected the world’s best system for becoming a truly effective Python 3.x developer. Follow it and you will succeed—just like the tens of millions of programmers he’s already taught. You bring the discipline, commitment, and persistence; the author supplies everything else. In Learn Python 3 the Hard Way, Zed Shaw taught you the basics of Programming with Python 3. Now, in Learn More Python 3 the Hard Way, you’ll go far beyond the basics by working through 52 brilliantly crafted projects. Each one helps you build a key practical skill, combining demos to get you started and challenges to deepen your understanding. Zed then teaches you even more in 12 hours of online videos, where he shows you how to break, fix, and debug your code. First, you’ll discover how to analyze a concept, idea, or problem to implement in software. Then, step by step, you’ll learn to design solutions based on your analyses and implement them as simply and elegantly as possible. Throughout, Shaw stresses process so you can get started and build momentum, creativity to solve new problems, and quality so you’ll build code people can rely on. Manage complex projects with a programmer’s text editor Leverage the immense power of data structures Apply algorithms to process your data structures Master indispensable text parsing and processing techniques Use SQL to efficiently and logically model stored data Learn powerful command-line tools and skills Combine multiple practices in complete projects It’ll be hard at first. But soon, you’ll just get it—and that will feel great! This course will reward you for every minute you put into it. Soon, you’ll go beyond merely writing code that runs: you’ll craft high-quality Python code that solves real problems. You’ll be a serious Python programmer. Perfect for Everyone Who’s Already Started Working with Python, including Junior Developers and Seasoned Python Pr

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值