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

Function bfs_find

graph/code7.cpp:16–41  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14}
15
16bool bfs_find(vector<int> vec[], vector<bool> &visited, vector<int> &parent, int source)
17{
18 queue<int> q;
19 q.push(source);
20 visited[source] = true;
21 while (q.empty() == false)
22 {
23 int curr = q.front();
24 q.pop();
25 for (int i = 0; i < vec[curr].size(); i++)
26 {
27 int adjacent = vec[curr][i];
28 if (visited[adjacent] == false)
29 {
30 visited[adjacent] = true;
31 q.push(adjacent);
32 parent[adjacent] = curr;
33 }
34 else if (visited[adjacent] == true && parent[curr] != adjacent)
35 {
36 return true;
37 }
38 }
39 }
40 return false;
41}
42
43bool bfs_rec(vector<int> vec[], int v)
44{

Callers 1

bfs_recFunction · 0.85

Calls 3

pushMethod · 0.45
popMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected