The main thing to keep in mind is that a priority_queue
is a sorted container, so it requires that you define a comparison for the objects being stored (which must follow a strict, weak ordering).
Since you talk about Dijkstra's algorithm, let's assume each vertex has a weight, and we want the vertices ordered by those weights.
struct vertex {
int x, y;
unsigned weight;
vertex(int x, int y, unsigned weight) : x(x), y(y), weight(weight) {}
bool operator <(vertex &other) { return weight < other.weight; }
};
Now a priority_queue of vertex objects is pretty easy:
std::priority_queue<vertex> vertices;
vertices.push(vertex(1, 2, 3));
vertices.push(vertex(0, 1, 2));
vertices.push(vertex(10, 11, 12));
std::cout << "Top = " << vertices.top() << "\n";
Edit: You'll need to define an insertion operator for that last line to work -- something like:
std::ostream &operator<<(std::ostream &os, vertex const &v) {
return os << "(" << v.x << ", " << v.y << '[' v.weight << "])\n";
}