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

后端 未结 5 447
醉话见心
醉话见心 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 03:11

    std::sort is not guaranteed to be stable (the term you were trying to think of). As you'd guess, std::stable_sort is guaranteed to be stable. std::stable_sort also provides a guarantee on worst-case complexity, which std::sort does not. std::sort is typically faster on average though.

提交回复
热议问题