algorithm - Storing vertex in a priority queue base on the weight of edges (C++) -
i having difficult time trying implement code. created class called vertex, each vertex points other vertices creating graph , adjacency list, implement created struct inside class vertex called edge. each edge has weight , vertex pointing to. heres code give better understanding.
vertex { public: void setpq() { for( int = 0; < adjlist.size(); ++i) { pq.push( adjlist[i].node ); } } private: struct edge { vertex* node; // vertex edge pointing int thatvertex; float weight; egde( ) { thatvertex = 0; weight = 0; } bool operator<( const edge & rhs) { return this.weight < rhs.weight; } }; vector< edge > adjlist; int thisvertex; int dist; bool known = false; piority_queue< vertex*, vector<vertex*>, edge > pq; };
i'm implementing dijkstra algorithm thats why have known , dist , other stuff. want in each vertex (or node) have priority queue , in queue, want store vertices this
pointing to. in other words, want store vertices adjacent this
vertex , sort using weight of edge. how suppose this? need compare weight of edge , store vertex of edge contains. have no idea how , don't think implementation correct. can me , explain how suppose this?
thank
Comments
Post a Comment