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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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 }
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply