Friday, 10 August 2012

Sort vector usinf make_heap and sort_heap (C++ code))


#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());

  make_heap(vector1.begin(), vector1.end());
  sort_heap(vector1.begin(), vector1.end());

  for (int i = 0; i < 5; ++i)
     cout << vector1[i];

  return 0;
}

No comments:

Post a Comment