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

Function cycleBFS

CPP/graphseries.cpp:5–30  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3using namespace std;
4
5bool cycleBFS(int node, vector<int> &vis, vector<int> arr[])
6{
7 queue<pair<int, int>> q;
8 q.push({node, -1});
9 vis[node] = 1;
10 while (!q.empty())
11 {
12 int n = q.front().first;
13 int p = q.front().second;
14 q.pop();
15 for (auto i : arr[n])
16 {
17 if (vis[i] == 0)
18 {
19 vis[i] = 1;
20 q.push({i, n});
21 }
22 else
23 {
24 if (i != p)
25 return true;
26 }
27 }
28 }
29 return false;
30}
31
32bool cycleDFS(int node, int parent, vector<int> &vis, vector<int> arr[])
33{

Callers

nothing calls this directly

Calls 2

pushMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected