Sort vector1 using push_heap and pop_heap
#include <iostream>
#include <cassert>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
vector<int> vector1(5);
for (int i = 0; i < 5; ++i)
vector1[i] = i;
random_shuffle(vector1.begin(), vector1.end());
for (int i = 2; i <= 5; ++i)
push_heap(vector1.begin(), vector1.begin() + i);
for (int i = 5; i >= 2; --i)
pop_heap(vector1.begin(), vector1.begin() + i);
for (int i = 0; i < 5; ++i)
cout << vector1[i];
return 0;
}
/*
01234
*/
Related examples in the same category