关于 Python 的内置 sort() 方法 [英] About Python's built in sort() method

查看:28
本文介绍了关于 Python 的内置 sort() 方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python 中的内置 sort() 方法使用什么算法?可以看看那个方法的代码吗?

What algorithm is the built in sort() method in Python using? Is it possible to have a look at the code for that method?

推荐答案

好的!代码在这里,从函数islt开始代码>并继续进行一段时间;-).正如克里斯的评论所暗示的那样,它是 C 代码.您还需要阅读 this 文本文件以获取文本说明、结果等

Sure! The code's here, starting with function islt and proceeding for QUITE a while;-). As Chris's comment suggests, it's C code. You'll also want to read this text file for a textual explanation, results, etc etc.

如果你更喜欢阅读 Java 代码而不是 C 代码,你可以看看 Joshua Bloch 在 Java 中的 timsort 实现(Joshua 也是在 1997 年实现了 Java 中仍在使用的修改后的归并排序的人,人们可以希望Java 最终会切换到他最近的 timsort 端口).

If you prefer reading Java code than C code, you could look at Joshua Bloch's implementation of timsort in and for Java (Joshua's also the guy who implemented, in 1997, the modified mergesort that's still used in Java, and one can hope that Java will eventually switch to his recent port of timsort).

关于 timsort 的 Java 端口的一些解释是这里,差异是这里(指向所有需要的文件),关键文件是 此处 -- FWIW,虽然我是比 Java 程序员更好的 C 程序员,但在这种情况下,我发现 Joshua 的 Java 代码总体上比 Tim 的 C 代码更具可读性;-)

Some explanation of the Java port of timsort is here, the diff is here (with pointers to all needed files), the key file is here -- FWIW, while I'm a better C programmer than Java programmer, in this case I find Joshua's Java code more readable overall than Tim's C code;-).

这篇关于关于 Python 的内置 sort() 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆