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

Function dijstra1

graph/code16.cpp:22–57  ·  view source on GitHub ↗

without priority queue

Source from the content-addressed store, hash-verified

20
21// without priority queue
22void dijstra1(vector<pair<int, int>> vec[], int v, int source)
23{
24 vector<bool> mst(v, false);
25 vector<int> dist(v, INT_MAX);
26 dist[source] = 0;
27
28 for (int i = 0; i < v; i++)
29 {
30 int u = -1;
31 for (int j = 0; j < dist.size(); j++)
32 {
33 if (mst[j] == false && (u == -1 || dist[j] < dist[u]))
34 {
35 u = j;
36 }
37 }
38 mst[u] = true;
39 for (int j = 0; j < vec[u].size(); j++)
40 {
41 int adjacent = vec[u][j].first;
42 int adj_weight = vec[u][j].second;
43
44 if (mst[adjacent] == false && dist[adjacent] > dist[u] + adj_weight)
45 {
46 dist[adjacent] = dist[u] + adj_weight;
47 }
48 }
49 }
50
51 cout << "Minimum distances(without priority queue) are: " << endl;
52 for (int i = 0; i < dist.size(); i++)
53 {
54 cout << dist[i] << " ";
55 }
56 cout << endl;
57}
58
59struct mycmp
60{

Callers 1

mainFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected