最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

std :: sort是否会更改相等元素的相对顺序?

SEO心得admin87浏览0评论
本文介绍了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.

发布评论

评论列表(0)

  1. 暂无评论