Does std::sort change the relative order of equal elements?

后端 未结 5 448
醉话见心
醉话见心 2021-01-12 02:45

Does the standard guarantee that order of equal elements will not change (eh, forgot the term for that) by using std::sort or do I need to consider an alternative solution

5条回答
  •  臣服心动
    2021-01-12 02:59

    No it explicitly does not guarantee this. If you need to maintain relative ordering use stable_sort instead.

    Documentation of sort which includes reference to equivalent elements

    • http://msdn.microsoft.com/en-us/library/ecdecxh1(VS.80).aspx

提交回复
热议问题