Hello :)
I need to pass to a prioriy queue a pair of integers and i want the top to be according to the smallest first integer and if two are equal then according to the second one(with ascending order).
Can someone help me? Because i have no big idea of classes and messed everything up here.
Thanks
You will need to define a function object that does the comparison for you as such:
1 2 3 4 5 6 7 8 9 10 11 12 13
class compare_pq
{
public:
booloperator() (int a, int b)
{
if (a < b) returntrue;
returnfalse;
}
};
//use it as:
std::priority_queue<int, std::vector<int>, compare_pq()> my_pq;
I haven't tested this, so it will probably not work out of the box - but it should give you an idea of what to do.
i use #define pii pair < int,int > every time i use pairs of integers so i know it does work ;p
Basically the code doesnt compile, so it doesnt work ;p
I'm not saying that won't work - I'm saying other coders will understand better what your intent is by using typedef.
Again: be more specific - if you have compiler errors, copy paste them (along with the code).
It's a lot easier for us to help you if you describe the problem clearly and concisely - that helps us help you better.