How to rearrange elements in vector in such a way that they form a heap for fast retrieval in C++

1 Answer

0 votes
#include <iostream>
#include <vector>
#include <algorithm>

using std::cout;
using std::endl;
using std::vector;

int main()
{
	vector<char> vec{ 'a', 'c', 'e', 'g', 'i' };
	
	make_heap(vec.begin(), vec.end());

	for (int i = 0; i <vec.size(); i++)
		cout << vec[i] << " ";

	cout << endl;

	return 0;
}


/*
run:

i g e a c

*/

 



answered May 19, 2018 by avibootz
...