std::stable_partition

来自cppreference.com

 
 
演算法庫
功能
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
修改序列操作
Original:
Non-modifying sequence operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
all_of
any_of
none_of
(C++11)
(C++11)
(C++11)
for_each
count
count_if
mismatch
equal
修改序列操作
Original:
Modifying sequence operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
分區操作
Original:
Partitioning operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
is_partitioned(C++11)
partition
partition_copy(C++11)
stable_partition
partition_point(C++11)
排序操作(排序的區間)
Original:
Sorting operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
is_sorted(C++11)
is_sorted_until(C++11)
sort
二進制搜索操作(排序的區間)
Original:
Binary search operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
設置操作(排序的區間)
Original:
Set operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
堆的操作
Original:
Heap operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
最小/最大操作
Original:
Minimum/maximum operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
數字操作
Original:
Numeric operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
C庫
Original:
C library
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
Defined in header <algorithm>
template< class BidirIt, class UnaryPredicate >
BidirIt stable_partition( BidirIt first, BidirIt last, UnaryPredicate p );
重新排序的範圍[first, last)在這樣一種方式中的元素,所有元素的謂詞p回報true之前的元素為謂詞p回報false。元素的相對順序被保存.
Original:
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.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目錄

[编辑] 參數

first, last -
範圍內的元素進行重新排序
Original:
the range of elements to reorder
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
p - unary predicate which returns ​true
如果該元素的,要責令之前的其他元素
Original:
if the element should be ordered before other elements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
.

The signature of the predicate function should be equivalent to the following:

bool pred(const Type &a);

The signature does not need to have const &, but the function must not modify the objects passed to it.
The type Type must be such that an object of type BidirIt can be dereferenced and then implicitly converted to Type. ​

Type requirements
-
BidirIt must meet the requirements of ValueSwappable and BidirectionalIterator.
-
The type of dereferenced BidirIt must meet the requirements of MoveAssignable and MoveConstructible.

[编辑] 返回值

迭代器到第二組的第一個元素
Original:
Iterator to the first element of the second group
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[编辑] 複雜性

究竟last-first應用程序的謂詞和最(last-first)*log(last-first)掉期,如果有足夠的內存或線性的掉期,如果有足夠的可用內存.
Original:
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.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[编辑] 為例

#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';
}

Output:

3 2 4 5 7 0 0 0 0

[编辑] 另請參閱

把一個範圍的元素分為兩組
Original:
divides a range of elements into two groups
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(函數模板) [edit]