I understood why a priority queue is needed for Dijkstra's algorithm, but i have a doubt when it comes to the implementation.Here's one of the implementations I came across : https://gist.github.com/johngian/1821625/.
I donot understand why the following wouldn't work (here's my code for comparing)
struct comp {
bool operator() (const pair<int, int> &a, const pair<int, int> &b) {
return a.second < b.second;
}
};
and my code for defining the priority queue is priority_queue <pair<int, int>, comp> Q
Also, why did he (and almost all other implementations) have an additional vector while defining a priority queue? Something similar to this priority_queue <pair<int, int>, vector <pair<int, int> > , comp > Q;
Any help is greatly appreciated :)








The second class template parameter of priority_queue is the class of the underlying container for the priority_queue.
You can read more about priority_queue constructors here
Or you can just google it)
Does this mean that a priority_queue is handled over a particular container rather than having its own container (unlike a standard queue) ??
then why does the following code work fine?
it produces the following output as expected :
because second argument has default value(vector)
yes
no. queue is used on top of deque
Yes, but you can set the type of the underlying container for queue too