What will be the output of the following C++ code? [code] #include <iostream> #include <algorithm> #include <vector> using

Ánh Dương

New member
What will be the output of the following C++ code?
Code:
    #include <iostream>
    #include <algorithm>
    #include <vector>
    using namespace std;
    int main ()  
    {
        int myints[] = {10, 20, 30, 5, 15};
        vector<int> v(myints, myints + 5);
        make_heap (v.begin(), v.end());
        pop_heap (v.begin(), v.end());
        v.pop_back();
        cout << v.front() << '\n';
        return 0;
    }
A. 10
B. 20
C. 30
D. 5
 
Answer: b
Explanation: In this program, We are forming a heap with the vector and then we are popping one element and finding the maximum element in the heap.
Output:
Code:
$ g++ style.cpp
$ a.out
20
 

Tìm kiếm

Back
Top