ronakchauhan's blog

By ronakchauhan, history, 9 years ago, In English

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

Full text and comments »

Tags c++, stl
  • Vote: I like it
  • +1
  • Vote: I do not like it