views:

53

answers:

1

I have a structure

struct state{
   int cur[10];
   int next[10];
   int priority;
};

and a priority queue of these states.How can I manage the priority queue so that front element is the element with the minimum value of 'priority' ?

+2  A: 

Never mind I found the answer http://www.cplusplus.com/reference/stl/priority_queue/priority_queue/

I'll just have to use an external comparator function.

But can someone explain this?

bool operator() (const int& lhs, const int&rhs) const         <<==========
  {
    if (reverse) return (lhs>rhs);
    else return (lhs<rhs);
  }
Ankit
This is implementing operator< to order your queue. This "reverse" part is whether you want the lowest numbers at the head of the queue or the highest; you should just pick the appropriate side of the conditional.
janm