Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,990 questions

51,935 answers

573 users

How to initialize priority_queue with array values in C++

1 Answer

0 votes
#include <iostream>
#include <queue>
 
int main()
{
    int arr[] = { 100, 88, 98, 80, 50, 12, 35, 70, 60, 97, 85, 89 } ;
    int size = sizeof(arr) / sizeof(arr[0]);

    std::priority_queue <int> pq(arr , arr + size) ;

    while (!pq.empty()) { 
        std::cout << pq.top() << " "; 
        pq.pop(); 
    }
}
 
 
 
 
 
/*
run:
  
100 98 97 89 88 85 80 70 60 50 35 12 
  
*/

 



answered May 13, 2022 by avibootz

Related questions

1 answer 134 views
1 answer 169 views
1 answer 160 views
1 answer 144 views
144 views asked Apr 23, 2018 by avibootz
1 answer 121 views
1 answer 163 views
1 answer 158 views
...