Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which sorting algorithm is used by Microsoft's STL::list::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();
like image 651
sharkin Avatar asked Feb 11 '26 18:02

sharkin


2 Answers

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

like image 138
Michael Burr Avatar answered Feb 15 '26 14:02

Michael Burr


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

like image 39
Jerry Coffin Avatar answered Feb 15 '26 15:02

Jerry Coffin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!