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

Function bfs

CPP/BFS_AND_DFS.cpp:19–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17// Repeat step 3 and 4 until the queue becomes empty.
18
19void bfs(int n, vector<int>adj[])
20{
21 vector<bool> visit(v,false);
22 queue<int> q;
23 q.push(n);
24 visit[n]=true;
25 while(!q.empty())
26 {
27 n=q.front();
28 cout<<n<<" ";
29 q.pop();
30 for(int i=0;i<adj[n].size();i++)
31 {
32 if(!visit[adj[n][i]])
33 {
34 q.push(adj[n][i]);
35 visit[adj[n][i]]=true;
36 }
37 }
38 }
39}
40
41/************************************* ALGORITHM FOR DEPTH FIRST SEARCH ******************************************************/
42

Callers 1

mainFunction · 0.70

Calls 3

pushMethod · 0.45
popMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected