How to have common priority queue | Min and Max | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to have common priority queue | Min and Max

Hi I have a vector of structure. I need to find out minimum and maximum data from same. It is decided on run time that what is needed like min or max heap. So, How to create priority queue object in such condition? For example for simplicity, if we need min and max values , We could use below two : priority_queue<int,vector<int>,greater<int> >pq; priority_queue<int,vector<int>,lesser<int> >pq; As rest all logic is same for me, how to declare pq data type dynamically?

2nd Nov 2022, 10:48 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
1 Answer
+ 1
To make it more clear , please refer code below: https://www.sololearn.com/compiler-playground/cUi6NdnsocWo What I need to do is to have common function for minFun() and maxFun() so that I dont have to repeat the same code again and again.
3rd Nov 2022, 6:51 AM
Ketan Lalcheta
Ketan Lalcheta - avatar