It should work just fine, if you want your elements sorted by their
second field. If that's not what you want, then you need a different
comparison function.
However, it should probably take its arguments by const reference or by
value. But since you haven't posted real code, nor provided any details
about what "doesn't work" means, it's not possible to tell what, if
anything, is wrong.
--
?? Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)-Hide quoted text -
- Show quoted text -
-------code-----
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cstdlib>
#include<cmath>
#include<list>
#include<stack>
#include<queue>
using namespace std;
bool cmp(const pair<PII,int> &x, const pair<PII,int> &y){
?? ?? ?? ?? return x.second < y.second;}
priority_queue<pair<PII, int>, vector<pair<PII,int> >, cmp>
heap; ?? //pair<pair<node I, node j>, weight>
int main(){
}
---------end---------
for simplicity, you can compile the code above.
I'm using vc8, and got the errors:
----------------------
------ Build started: Project: pku, Configuration: Debug Win32 ------
Compiling...
a.cpp
..\a.cpp(14) : error C2065: 'PII' : undeclared identifier
..\a.cpp(17) : error C3203: 'pair' : unspecialized class template
can't be used as a template argument for template parameter '_Ty',
expected a real type
..\a.cpp(17) : error C3203: 'pair' : unspecialized class template
can't be used as a template argument for template parameter '_Ty',
expected a real type
..\a.cpp(17) : error C2923: 'std::priority_queue' : 'cmp' is not a
valid template type argument for parameter '_Pr'
?? ?? ?? ?? ..\a.cpp(14) : see declaration of 'cmp'
..\a.cpp(17) : error C2133: 'heap' : unknown size
..\a.cpp(17) : error C2512: 'std::priority_queue' : no appropriate
default constructor available
------------------------- Hide quoted text -
- Show quoted text -