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

Function find_sd

graph/code6.cpp:13–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11}
12
13void find_sd(vector<int> vec[], int v, int source)
14{
15 vector<bool> visited(v, false);
16 vector<int> dist(v, INT_MAX);
17
18 queue<int> q;
19 q.push(source);
20 dist[source] = 0;
21 visited[source] = true;
22
23 while (q.empty() == false)
24 {
25 int curr = q.front();
26 q.pop();
27 // cout<<"curr: "<<curr<<endl;
28 for (int i = 0; i < vec[curr].size(); i++)
29 {
30 int adjacent = vec[curr][i];
31 // cout<<"curr: "<<curr<<" adjacent: "<<adjacent<<endl;
32 if (visited[adjacent] == false)
33 {
34 dist[adjacent] = dist[curr] + 1;
35 visited[adjacent] = true;
36 q.push(adjacent);
37 }
38 }
39 }
40 cout << "CHECK DISTANCE: " << endl;
41 for (int i = 0; i < dist.size(); i++)
42 {
43 cout << dist[i] << " ";
44 }
45 cout << endl;
46 return;
47}
48
49int main()
50{

Callers 1

mainFunction · 0.85

Calls 3

pushMethod · 0.45
popMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected