Need help with C++ STL & Dijkstra

Правка en1, от ronakchauhan, 2017-04-16 17:30:49

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 :)

Теги c++, stl

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский ronakchauhan 2017-04-16 17:30:49 844 Initial revision (published)