Skip to content

Commit

Permalink
Added solution - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
sainikcodes24x7 committed Jul 16, 2023
1 parent c45b19c commit 1d84df6
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions BFS of graph - GFG/bfs-of-graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ class Solution {
// Code here
queue<int>q;
vector<int>ans;
vector<int>vis(V+1,0);
vis[0]=1;
vector<bool>vis(V+1,0);
q.push(0);
while(!q.empty()){
auto top=q.front();
vis[0]=1;
while(q.size()!=0){
int curr=q.front();
q.pop();
ans.push_back(top);
for(auto nbr:adj[top]){
for(auto nbr:adj[curr]){
if(!vis[nbr]){
vis[nbr]=1;
q.push(nbr);
}
}
ans.push_back(curr);
}
return ans;
}
Expand Down

0 comments on commit 1d84df6

Please sign in to comment.