Der Andere wrote:
bool comp (Vertex* v1, Vertex* v2)
{
return v1->a < v2->a;
}
int main()
{
std::priority_queue<Vertex*> pv(comp());
There are two things which are wrong with the above code:
- The type of the comparator is part of the priority queue's type.
That is, the type in the above line would read something like
this:
std::priority_queue<Vertex*, std::vector<Vertex*>,
bool(*)(Vertex*, Vertex*)>
- 'comp' is a function, not a type. To pass 'comp' to a function
like the constructor you just use 'comp':
pv(comp)
Of course, 'std::less<Vertex*>' would indeed compare the pointer
values.
Since you apparently want to use your priority queue with a graph,
you might want to use a priority queue allowing changing a nodes
priority. 'std::priority_queue' does not allow this. I have a
made a collection of priority queues publically available, some of
which allow this (e.g. the Fibonacci-heap and a specialized d-heap
implementation). These can be downloaded from
<http://www.dietmar-kuehl.de/heaps.tar.gz>.
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting