11

I couldn't find any definitive answer to this question.

I suppose most implementation use merge sort that is stable but, is the stability a requirement or a side effect?

3 Answers 3

23

C++ Standard ISO/IEC 14882:2003 says:

23.2.2.4/31

Notes: Stable: the relative order of the equivalent elements is preserved. If an exception is thrown the order of the elements in the list is indeterminate.

2
  • 3
    +1. SGI and Stroustrup are both correct but not the "definitive answer". ISO 14882 is.
    – MSalters
    Mar 4, 2009 at 11:30
  • Only great answers but I admit this is the best. ;)
    – Edouard A.
    Mar 4, 2009 at 15:01
12

Yes, std::list<>::sort is guaranteed to be stable.

See http://www.sgi.com/tech/stl/List.html

0
10

According to "The C++ Programming Language" (Stroustrup p470), yes, stl::list<>::sort is stable.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.