Welcome to collectivesolver - Programming & Software Q&A with Examples. A website you can trust. All programs tested and work.

Contact: aviboots(AT)netvision.net.il


Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Relieve stress, calm your mind and boost confidence

100%
Managed VPS Hosting
Affordable. Secure. Your Own Virtual Private Hosting. Faster than AWS and Rackspace

Bonsai Boy of New York Bonsai Trees and Accessories
Liquid Web - Highest Level of Performance and Security with Managed Dedicated Servers

Disclosure We are a professional Programming & Software Q&A website, that receives compensation from some of the links whose we show you with Information. It means that my content may contain affiliate links.

23,335 questions

30,538 answers

573 users

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 by avibootz
...