c++ - 什么时候对标量调用 stable_sort()?

标签 c++ algorithm sorting primitive stable-sort

在标量类型(即 intlong、等)与默认比较器?

如果是这样,你应该什么时候做?

如果不是,那么为什么标准库不直接将此类调用转发给 sort?那不是更快吗?

最佳答案

稳定排序仅在您排序的项目具有 satellite information 时才有用。 .


摘自 CLRS(算法导论,第 3 版):

"In practice, the numbers to be sorted are rarely isolated values. Each is usually part of a collection of data called a record. Each record contains a key, which is the value to be sorted. The remainder of the record consists of satellite data, which are usually carried around with the key. In practice, when a sorting algorithm permutes the keys, it must permute the satellite data as well."


当排序稳定时,这意味着已排序数组中的关系被项目的原始顺序打破。如果您只对 intlong 类型进行排序,则不需要稳定排序。

关于c++ - 什么时候对标量调用 stable_sort()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17256810/

相关文章:

mongodb - 在聚合中使用带限制和跳过的排序时出现 Mongodb 重复问题

c++ - 什么是 undefined reference /未解析的外部符号错误,我该如何解决?

c++ - 内存分配责任

algorithm - "Time Aware"指数移动平均线

algorithm - 凸包排序步骤

javascript - 根据数组内关联对象的属性对 div 元素进行排序

java - 对包含带数字的字符串的文件名数组进行排序

c++ - 闭合贝塞尔曲线

c++ - 抑制纯虚函数调用模态对话框并静默崩溃

algorithm - 高级与低级算法实现