std::stable_partition

来自cppreference.com
P12bot留言 | 贡献2014年10月27日 (一) 00:40的版本 (Fix some translations)

<metanoindex/>

 
 
算法库
受约束算法及范围上的算法 (C++20)
包含算法例如 ranges::copy, ranges::sort, ...
执行策略 (C++17)
排序和相关操作
划分操作
排序操作
二分搜索操作(在已划分范围上)
集合操作(在有序范围上)
归并操作(在有序范围上)
堆操作
最小/最大操作
(C++11)
(C++17)
字典序比较操作
排列操作
C 库

数值运算
(C++11)                       
在未初始化内存上的操作
 
在标头 <algorithm> 定义
template< class BidirIt, class UnaryPredicate >
BidirIt stable_partition( BidirIt first, BidirIt last, UnaryPredicate p );
重新排序的范围[first, last)在这样一种方式中的元素,所有元素的谓词p回报true之前的元素为谓词p回报false。元素的相对顺序被保存.
原文:
Reorders the elements in the range [first, last) in such a way that all elements for which the predicate p returns true precede the elements for which predicate p returns false. Relative order of the elements is preserved.
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。

参数

first, last -
范围内的元素进行重新排序
原文:
the range of elements to reorder
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。
p -
如果该元素的,要责令之前的其他元素
原文:
if the element should be ordered before other elements
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。
则返回 ​true 的一元谓词。

对每个(可为 const 的) VT 类型参数 v ,其中 VTBidirIt 的值类型,表达式 p(v) 必须可转换到 bool,无关乎值类别,而且必须不修改 v 。从而不允许 VT& 类型参数,亦不允许 VT ,除非对 VT 而言移动等价于复制(C++11 起)。 ​

类型要求

Template:par req concept Template:par req concept deref

返回值

迭代器到第二组的第一个元素
原文:
Iterator to the first element of the second group
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。

复杂度

究竟last-first应用程序的谓词和最(last-first)*log(last-first)掉期,如果有足够的内存或线性的掉期,如果有足够的可用内存.
原文:
Exactly last-first applications of the predicate and at most (last-first)*log(last-first) swaps if there is insufficient memory or linear number of swaps if sufficient memory is available.
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。

示例

#include <iostream>
#include <algorithm>

int main()
{
    std::vector<int> v{0, 0, 3, 0, 2, 4, 5, 0, 7};
    std::stable_partition(v.begin(), v.end(), [](int n){return n>0;});
    for (int n : v) {
        std::cout << n << ' ';
    }
    std::cout << '\n';
}

输出:

3 2 4 5 7 0 0 0 0

另请参阅

将范围中元素分为两组
(函数模板) [编辑]