std :: sort是否会更改相等元素的相对顺序? [英] Does std::sort change the relative order of equal elements?

查看:46
本文介绍了std :: sort是否会更改相等元素的相对顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标准是否通过使用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.

这篇关于std :: sort是否会更改相等元素的相对顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆