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

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

问题描述

什么算法在Python中的排序()方法使用内置的?是否有可能有一个看$ C $下那个方法?

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

推荐答案

当然!在code的<一个href="http://svn.python.org/view/python/trunk/Objects/listobject.c?revision=69227&view=markup">here,首先是功能 ISLT 并继续相当长的一段;-)。随着克里斯的意见建议,这是C $ C $℃。你还需要读<一href="http://svn.python.org/view/python/trunk/Objects/listsort.txt?revision=69846&view=markup">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.

如果您preFER读取Java code比C code,你可以看看约书亚·布洛赫的实施timsort并用于Java(约书亚的还谁实施的家伙,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移植的部分解释是这里的差异是这里(带指针的所有需要​​的文件),密钥文件是<一个href="http://hg.openjdk.java.net/jdk7/tl/jdk/file/bfd7abda8f79/src/share/classes/java/util/TimSort.java">here - FWIW,而我是一个更好的C程序员比Java程序员,在这种情况下,我觉得约书亚的Java code比添公司的C code更具可读性的整体; - 。)

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天全站免登陆