We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 61f8f05 commit 9a64aa0Copy full SHA for 9a64aa0
bfs_graph/code.cpp
@@ -0,0 +1,33 @@
1
+class Solution {
2
+ public:
3
+ // Function to return Breadth First Traversal of given graph.
4
+ vector<int> bfsOfGraph(int V, vector<int> adj[]) {
5
+ // Code here
6
+ bool vis[V];
7
+ for(int i=0;i<V;i++){
8
+ vis[i]=false;
9
+ }
10
+
11
+ vis[0]=true ;
12
13
+ queue<int>q;
14
+ q.push(0);
15
+ vector<int>res;
16
17
+ while (!q.empty()){
18
+ int s=q.front();
19
+ res.push_back(s);
20
21
+ q.pop();
22
+ for(auto i : adj[s]){
23
+ if(!vis[i]){
24
+ q.push(i);
25
+ vis[i]=true;
26
27
28
29
30
+ return res;
31
32
33
+};
0 commit comments