Page 1 of 1

Hi can you please write this for me in c++ for the higlighted bit thanks, using graph class also not sure what to declar

Posted: Fri May 20, 2022 6:40 pm
by answerhappygod
Hi can you please write this for me in c++ for the
higlighted bit thanks, using graph class also not sure what to
declare "t" and cost in the method or function
implement Dijkstra’s algorithm using the adjacency
list
Answer:
Algorithm Dijkstra (Graph, SourceNode)
//the Graph contains vertices V={A,B...} and edges
E={(A,B,cost)...}
Require: array of distances d[N], array of states s[N], node
current
1 d[SourceNode]=0;
2 s[SourceNode]=p;
3 current=SourceNode;
4 for each vertex v in Graph{
5 if (v != SourceNode) {
6 d[v] = infinite, s[v] = t;
7 }
8 while there is any vertex v with state s[v]==t
{
9 for each neighbour v of current{
10 d[v] = min (d[v], d[current] + cost(current, v);//the
cost(current,v)
comes from E{}
11 }
12 current = v with minimum d[v] and with state
s[v]==t;
13 s[current] = p;
14 }