Which sorting algorithm is used by Microsoft's STL::list::sort()?

为君一笑 提交于 2019-12-22 10:57:10

问题


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();

回答1:


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).




回答2:


At least in recent versions (e.g. VC++ 9.0/VS 2008) MS VC++ uses a merge-sort.




回答3:


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.




回答4:


To my knowledge it is Introsoft: http://en.wikipedia.org/wiki/Introsort



来源:https://stackoverflow.com/questions/1717899/which-sorting-algorithm-is-used-by-microsofts-stllistsort

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!