The Wayback Machine - https://web.archive.org/web/20180506105840/http://ja.cppreference.com:80/w/cpp/algorithm/stable_partition
名前空間
変種
操作

std::stable_partition

提供: cppreference.com
< cpp‎ | algorithm

 
 
アルゴリズムライブラリ
実行ポリシー (C++17)
非変更シーケンス操作
(C++11)(C++11)(C++11)
(C++17)
変更シーケンス操作
未初期化記憶域の操作
分割操作
stable_partition

ソート操作
バイナリサーチ操作
集合操作 (ソート済み範囲に対する)
ヒープ操作
(C++11)
最小/最大演算
(C++11)
(C++17)
順列
数値演算
C のライブラリ
 
ヘッダ <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 -
要素は他の要素の前に発注する必要があります
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.
true を返す単項述語。

述語関数のシグネチャは以下と同等なものであるべきです。

 bool pred(const Type &a);

シグネチャが const& を持つ必要はありませんが、関数は渡されたオブジェクトを変更してはなりません。
Type は型 BidirIt のオブジェクトの逆参照から暗黙に変換可能なものでなければなりません。 ​

型の要件
-
BidirItValueSwappable および 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';}

出力:

3 2 4 5 7 0 0 0 0

[編集]参照

指定範囲の要素を2つのグループに分割します
(関数テンプレート)[edit]
close