How to initialize priority_queue with vector values in C++

1 Answer

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

int main()
{
    std::vector<int> v = { 100, 88, 98, 80, 50, 12, 35, 70, 60, 97, 85, 89  };

    std::priority_queue <int> pq( v.begin() , v.end() );

    while (!pq.empty()) { 
        std::cout << pq.top() << " "; 
        pq.pop(); 
    }
}





/*
run:
 
100 98 97 89 88 85 80 70 60 50 35 12 
 
*/

 



answered May 12, 2022 by avibootz

Related questions

...