-1

How does lastline work?
Will it make max heap or min heap?

int myints[] = {10,20,30,5,15};

std::vector<int> v(myints,myints+5);

std::make_heap (v.begin(),v.end());
Guvante
  • 18,775
  • 1
  • 33
  • 64
Prashant Gupta
  • 103
  • 2
  • 12
  • 3
    Why don't you look at the documentation for [`std::make_heap`](http://en.cppreference.com/w/cpp/algorithm/make_heap) ? – Borgleader Jan 30 '15 at 16:49
  • Is it possible to create min heap using make_heap. I saw document but I didnt see ? – Prashant Gupta Jan 30 '15 at 16:54
  • @PrashantGupta: I found a [stackoverflow question](http://stackoverflow.com/questions/7681779/easy-way-to-maintain-a-min-heap-with-stl) about a min heap. – Guvante Jan 30 '15 at 16:55

1 Answers1

0

std::make_heap is part of the "heap" functions in the standard library. They all work by using an underlying data store. In the case you gave you are using a std::vector as your data store.

Calling std::make_heap passing in the range of your data store will heapify its contents, causing the first element to the largest in value and satisfying all requirements for std::push_heap and std::pop_head.

How does lastline work ? will it make max heap or min heap?

It makes a max heap within the std::vector supplied (v).

Guvante
  • 18,775
  • 1
  • 33
  • 64