Priority Queue
Posted by Whitney Young Tue, 30 May 2006 23:11:00 GMT
This is more of a note to myself, but I’ve had to look up how to initialize a priority queue with a custom comparison function in C++ too many times (and it’s always hard to find). It’s really not hard, there’s just not one good online source for the STL (someone please point one out if there is - or even a good pocket reference type book). Anyway, here’s the code…. not too hard:
#include "event.h"
#include <queue>
using std::priority_queue;
class greater {
public: int operator() (Event *x, Event *y) { return *x > *y; }
};
priority_queue< Event *, vector<Event *>, greater > _event_queue;(Also just discovered the <typo:code></typo:code> code block tag for typo. Nice.)

