1.

Which of the following is correct syntax of making heap from a vector v?(a) make_heap(v.elements);(b) make_heap(v);(c) make_heap(v.end(), v.begin());(d) make_heap(v.begin(), v.end());This question was posed to me during an interview.My question is from STL in portion Class Hierarchies, Library & Containers of C++

Answer»

Correct ANSWER is (d) make_heap(v.begin(), v.end());

The explanation: To construct HEAP USNG the vector elements one need to use the FOLLOWING syntax make_heap(v.begin(), v.end()); which is taking the ITERATOR to first and last element of the vector using which elements of vector can be accessed and heap can be constructed.



Discussion

No Comment Found

Related InterviewSolutions