在标量类型(即 int
、long
、等)与默认比较器?
如果是这样,你应该什么时候做?
如果不是,那么为什么标准库不直接将此类调用转发给 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."
当排序稳定时,这意味着已排序数组中的关系被项目的原始顺序打破。如果您只对 int
和 long
类型进行排序,则不需要稳定排序。
关于c++ - 什么时候对标量调用 stable_sort()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17256810/