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

编程入门 行业动态 更新时间:2024-10-11 17:27:02
本文介绍了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是否会更改相等元素的相对顺序?

本文发布于:2023-11-30 06:06:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648972.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:是否会   顺序   元素   std   sort

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!