priority_queue

Hi, I know what's Heap, HeapSort, I know the ways of implementing this data structure. But know I would like to use the STL priority_queue instead, so that STL will do the job of implementing for me. However, I came across a problem, which is that I don't know how to adjust the priority_queue, so that it stores more complicated types. Such as
1
2
3
4
5
typedef struct {
    int No1;
    int No2;
    // ... etc.
} moreComplicatedType;

I want it to store only according to (for example) No1. Is there a way I can set up a compare function or something like that?

Thanks for help and Happy new year!
1
2
3
4
5
6
7
8
9
10
11
12
13
class mycomparison
{
  bool reverse;
public:
  mycomparison(const bool& revparam=false)
    {reverse=revparam;}
  bool operator() (const int& lhs, const int&rhs) const
  {
    if (reverse) return (lhs>rhs);
    else return (lhs<rhs);
  }
};

Why does this code use variable "reverse" when it's anyway initialized on false?
Topic archived. No new replies allowed.