Cpp-standard-library-cpp-algorithm-is-permutation-v2
提供:Dev Guides
C ++アルゴリズムライブラリ-is_permutation()関数
説明
- C ++関数* std
- algorithm :: is_permutation()*は、シーケンスが他の順列であるかどうかをテストします。 比較のために `+ binary predicate +`を使用します。
宣言
- 以下は、std
- algorithmヘッダーからのstd :: algorithm :: is_permutation()関数の宣言です。
C 11
template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, BinaryPredicate pred);
パラメーター
- first1 -最初のシーケンスの初期位置に反復子を入力します。
- last1 -最初のシーケンスの最終位置に反復子を入力します。
- first2 -2番目のシーケンスの初期位置に反復子を入力します。
- pred -2つの引数を受け取り、boolを返すバイナリ述語。
戻り値
最初の範囲が別の範囲の順列である場合はtrueを返し、そうでない場合はfalseを返します。
例外
バイナリ述語またはイテレータの操作が例外をスローする場合、例外をスローします。
無効なパラメータは未定義の動作を引き起こすことに注意してください。
時間の複雑さ
二次。
例
- 次の例は、std
- algorithm :: is_permutation()関数の使用法を示しています。
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool ignore_case(char a, char b) {
return (tolower(a) == tolower(b));
}
int main(void) {
vector<char> v1 = {'A', 'B', 'C', 'D', 'E'};
vector<char> v2 = {'a', 'b', 'c', 'd', 'e'};
bool result;
result = is_permutation(v1.begin(), v1.end(), v2.begin());
if (result == false)
cout << "Both vector doesn't contain same elements." << endl;
result = is_permutation(v1.begin(), v1.end(), v2.begin(), ignore_case);
if (result == true)
cout << "Both vector contains same elements." << endl;
return 0;
}
上記のプログラムをコンパイルして実行すると、次の結果が生成されます-
Both vector doesn't contain same elements.
Both vector contains same elements.