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