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

后端 未结 5 473
醉话见心
醉话见心 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:21

    From C++ reference: here

    Elements that would compare equal to each other are not guaranteed to keep their original relative order.

    You might want stable_sort, but note that it's not as fast (in average)

提交回复
热议问题