私は3つのパラメータを取るpush_heap関数は何をするのだろうか?C++のpush_heap関数は何をしますか?
#include <iostream>
#include <cassert>
#include <algorithm>
#include <vector>
using namespace std;
class HeapCompare_f
{
public:
bool operator() (int x, int y) const
{
return x > y;
}
};
int main()
{
vector<int> vector1(5);
for (int i = 0; i < 5; ++i)
vector1[i] = 5-i;
for (int i = 0; i < 5; ++i)
cout << vector1[i];
cout << endl;
push_heap(vector1.begin(), vector1.end(),HeapCompare_f());
for (int i = 0; i < 5; ++i)
cout << vector1[i];
cout << endl;
return 0;
}
このコードの出力は
54321
15324
また、私はどのように私はCにその機能を実装することができますだろうか?
このコードは、 'push_heap'の前提条件に違反し、指定された範囲が最後の要素を除く有効なヒープであるため、正しくありません。 – interjay
真剣に? http://en.cppreference.com/w/cpp/algorithm/push_heap –