Cpp-standard-library-cpp-algorithm-is-heap-until-v1
提供:Dev Guides
C ++アルゴリズムライブラリ-is_heap_until()関数
説明
- C ++関数* std
- algorithm :: is_heap_until()*は、最大ヒープ条件に違反するシーケンスから最初の要素を見つけます。 比較のために `+ operator <+`を使用します。
宣言
- 以下は、std
- algorithmヘッダーからのstd :: algorithm :: is_heap_until()関数の宣言です。
C 11
template <class RandomAccessIterator>
RandomAccessIterator is_heap_until(RandomAccessIterator first,
RandomAccessIterator last);
パラメーター
- first -初期位置へのランダムアクセス反復子。
- last -最終位置へのランダムアクセス反復子。
戻り値
最大ヒープ条件に違反する最初の要素へのイテレータを返します。 シーケンス全体が有効な最大ヒープである場合、 `+ last +`を返します。
例外
要素比較またはイテレータの操作が例外をスローした場合、例外をスローします。
無効なパラメータは未定義の動作を引き起こすことに注意してください。
時間の複雑さ
リニア。
例
- 次の例は、std
- algorithm :: is_heap_until()関数の使用法を示しています。
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void) {
vector<int> v = {4, 3, 5, 1, 2};
auto result = is_heap_until(v.begin(), v.end());
cout << *result << " is the first element which "
<< "violates the max heap." << endl;
v = {5, 4, 3, 2, 1};
result = is_heap_until(v.begin(), v.end());
if (result == end(v))
cout << "Entire range is valid heap." << endl;
return 0;
}
上記のプログラムをコンパイルして実行すると、次の結果が生成されます-
5 is the first element which violates the max heap.
Entire range is valid heap.