Program#include “ stdio.h “
#include “ conio.h “
#define n 10
void bfs(int adj[][n],int visited[],int start)
{
int q[n],rear=-1,front=-1,i;
q[++rear]=start;
visited[start]=1;
while(rear!=front)
{
start=q[++front];
if(start==q)
printf("10-");
else
printf("%c-",start+65);
for(i=0;i < n;i++) { if(adj[start][i]&&!visited[i]) { q[++rear]=i; visited[i]=1; } } } } void main() { int adj[n][n]={{0,1,1,0,0,0,0,0,0,1},{0,0,0,0,1,0,0,0,0,1}, {0,0,0,0,1,0,1,0,0,0},{1,0,1,0,0,1,1,0,0,1}, {0,0,0,0,0,0,1,1,0,0},{0,0,0,1,0,0,0,1,0,0}, {0,0,0,0,0,0,0,1,1,1},{0,0,1,0,0,0,0,0,0,0}, {0,0,0,1,0,0,0,0,0,0},{0,0,1,0,0,0,0,1,1,0}};.
int visited[n]={0}; clrscr();
printf("\n\t\t\t------------------------------");
printf("\n\n");
printf("BFS Traverse:");
bfs(adj,visited,0);
getch();
}
OutputBFS Traverse: A-B-C-J-E-G-H-I-D-F-