Created
February 23, 2014 05:37
-
-
Save Shafaet/9167456 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vector<int>G[100]; | |
void bfs(int n,int src) | |
{ | |
queue<int>Q; | |
Q.push(src); | |
int visited[100]={0},level[100]; | |
int parent[100]; | |
visited[src]=1; | |
level[src]=0; | |
while(!Q.empty()) | |
{ | |
int u=Q.front(); //Q এর সামনের নোড নিয়ে আমরা কাজ করবো | |
for(int i=0;i<G[u].size();i++) | |
{ | |
int v=G[u][i]; | |
if(!visited[v]) | |
{ | |
level[v]=level[u]+1; | |
parent[v]=u; | |
visited[v]=1; | |
Q.push(v); | |
} | |
} | |
Q.pop(); | |
} | |
for(int i=1;i<=n;i++) | |
printf("%d to %d distance %d",src,i,level[i]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment