Microsoft 的 STL::list::sort() 使用哪种排序算法?
注意:我不小心发布了这个问题,但没有指定我正在使用哪种 STL 实现,并且我觉得它无法真正更新,因为它会使大部分答案变得过时。
因此,正确的问题是 - 下面的代码中使用哪种排序算法,假设我正在使用 Microsoft Visual C++ 的 STL 库?:
list<int> mylist;
// ..insert a million values
mylist.sort();
Note: I accidentally posted this question without specifying which STL implementation I was using, and I felt it can't really be updated since it would render most of its answers obsolete.
So, the correct question goes - which sorting algorithm is used in the below code, assuming I'm using the STL library of Microsoft Visual C++?:
list<int> mylist;
// ..insert a million values
mylist.sort();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为了让您不必依赖二手信息,排序代码位于
list
标头中 - 大约 35 行。似乎是一种修改后的迭代(非递归)合并排序,最多有 25 个容器(我不知道这种合并排序变体是否有特定的名称)。
Just so you don't have to rely on second hand information, the the sort code is right in the
list
header - it's about 35 lines.Appears to be a modified iterative (non-recursive) merge sort with up to 25 bins (I don't know if there's a particular name for this variant of merge sort).
至少在最近的版本(例如VC++ 9.0/VS 2008)中,MS VC++ 使用合并排序。
At least in recent versions (e.g. VC++ 9.0/VS 2008) MS VC++ uses a merge-sort.
MS VC6 附带的 STL 是 PJ Plauger 版本的库 (Dinkumware),它在
std::list<>::sort()
中使用合并排序。我不知道 MS 软件包的更高版本。STL that came with MS VC6 was the P. J. Plauger's version of the library (Dinkumware) and it used merge-sort in
std::list<>::sort()
. I dont know about later versions of MS's package.据我所知,它是 Introsoft: http://en.wikipedia.org/wiki/Introsort
To my knowledge it is Introsoft: http://en.wikipedia.org/wiki/Introsort