MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / shortest_dist

Function shortest_dist

graph/code13.cpp:63–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

61}
62
63void shortest_dist(vector<pair<int, int>> vec[], vector<int> &sort_vec, int v, int source)
64{
65 vector<int> dist(v, INT_MAX);
66 dist[source] = 0;
67
68 int pos = -1;
69
70 for (int i = 0; i < sort_vec.size(); i++)
71 {
72
73 // cout << sort_vec[i] << " ";
74 if (sort_vec[i] == source)
75 {
76 pos = i;
77 break;
78 }
79 }
80
81 // cout<<"pos: "<<pos<<endl;
82
83 for (int i = pos; i < sort_vec.size(); i++)
84 {
85 int curr = sort_vec[i];
86
87 // cout << "curr: " << curr << endl;
88
89 for (int j = 0; j < vec[curr].size(); j++)
90 {
91 int adjacent = vec[curr][j].first;
92
93 // cout << adjacent << endl;
94
95 if (dist[adjacent] > dist[curr] + vec[curr][j].second)
96 {
97 dist[adjacent] = dist[curr] + vec[curr][j].second;
98 }
99 }
100 }
101
102 cout << "CHECK SHORTEST DISTANCE:" << endl;
103 for (int i = 0; i < dist.size(); i++)
104 {
105 cout << dist[i] << " ";
106 }
107 cout << endl;
108}
109
110int main()
111{

Callers 1

mainFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected