标准是否通过使用std :: sort保证相等元素的顺序不变(即,忘记了该术语),还是我需要考虑一种替代解决方案来实现这一目标?
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 to achieve this goal?
推荐答案std :: sort 不能保证稳定(您要考虑的术语).如您所料,保证 std :: stable_sort 是稳定的. std :: stable_sort 还提供了最坏情况下的复杂性的保证,而 std :: sort 则没有.但是, std :: sort 通常通常更快.
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.