简体   繁体   English

Common Lisp中使用什么算法进行“排序”功能?

[英]What algorithm is used for “sort” function in Common Lisp?

I guess, it might be implementation dependent, so the question isn't entirely correct. 我猜,它可能是依赖于实现的,所以问题并不完全正确。 Still in looks like some kind of comparing sort with n(log n) average complexity. 仍然看起来像某种比较排序与n(log n)平均复杂度。 To rephrase my question in more answerable manner: is there any reason to write own quick sort or merge sort or any other comparing sort other then didactic? 以更负责任的方式重新解释我的问题:有没有理由编写自己的快速排序或合并排序或任何其他比较排序,然后说教?

Yes, the algorithm is implementation defined (imagine prescribing a specific algorithm in the standard, and then someone comes a long and invents a better general purpose one). 是的,算法是实现定义的(想象一下在标准中规定一个特定的算法,然后有人来了很长时间并发明了一个更好的通用目标)。 You can look up the standard yourself (just google "clhs sort"). 您可以自己查找标准(只需谷歌“clhs sort”)。

The implementation provided sort and stable-sort should generally cover almost any sorting need you have. 实现提供sortstable-sort通常应该涵盖几乎所有排序需求。 I can imagine the following reasons to write your own: 我可以想象写下你自己的以下理由:

  • You need hooks into specific stages of the sorting procedure 您需要挂钩到排序过程的特定阶段
  • You need only partial sorting 您只需要部分排序
  • You need a specific algorithm for your problem domain 您需要针对问题域的特定算法
  • You want to compare different algorithms 您想要比较不同的算法

In any case, I should recommend to take a deep look into the existing sorting implementations in order not to miss possible optimizations (which is generally relevant in the context of sorting). 在任何情况下,我都应该建议深入研究现有的排序实现,以免错过可能的优化(通常在排序的上下文中相关)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM