stable_sort
template <class RandomAccessIterator> void stable_sort ( RandomAccessIterator first, RandomAccessIterator last );
void stable_sort ( RandomAccessIterator first, RandomAccessIterator last,
Compare comp );
Sort elements preserving order of equivalents
Sorts the elements in the range
[first,last) into ascending order, like
sort, but
stable_sort grants that the relative order of the elements with equivalent values is preserved.
The elements are compared using operator< for the first version, and comp for the second.
The elements are compared using operator< for the first version, and comp for the second.
Parameters
-
first, last
- [first,last) comp
- Comparison function object that, taking two values of the same type than those contained in the range, returns true if the first argument goes before the second argument in the specific strict weak ordering(严格偏序) it defines, and false otherwise.
-
- bool cmp(Record a,Record b);
- 默认是增序,即若a.key < b.key, return true,按增序排列。
- 若a.key > b.key return true,则实际是按减序排列的
- 也可以定义相等时的大小比较来定义第二阶的排序
-
-
1046. Plane Spotting
-
本文介绍C++标准库中的stable_sort函数,该函数对指定范围内的元素进行排序,并保持相同元素的相对顺序不变。文中提供了使用默认比较及自定义比较函数的例子。
8861

被折叠的 条评论
为什么被折叠?



