[go: up one dir, main page]

0% found this document useful (0 votes)
5 views2 pages

Ds 10 B

Uploaded by

akbhai000008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Ds 10 B

Uploaded by

akbhai000008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

/**********************************************************************************

EXPERIMENT NO.10(B)
*********************************************************************************

AIM: Implement Graph Traversal techniques: Breadth First Search.

Class: Roll No.:

**********************************************************************************/

#include<stdio.h>
#include<conio.h>
#define MAX 6
void bfs(int[MAX][MAX],int[MAX],int);
void main()
{
int adj[MAX][MAX];
int visited[MAX]={0},i,j;
clrscr();
printf("\nenter the adjacency matrix: ");
for(i=0;i<MAX;i++)
{
for(j=0;j<MAX;j++)
{
scanf("%d",&adj[i][j]);
}
}
printf("\nBFS Traversal is ");
bfs(adj,visited,0);
printf("\n");
getch();
}

void bfs(int adj[][MAX],int visited[],int start)


{
int queue[MAX];
int rear=-1,front=-1,i;
queue[++rear]=start;
visited[start]=1;
while(rear!=front)
{
start=queue[++front];
printf("%c ",start+65);
for(i=0;i<MAX;i++)
{
if(adj[start][i]==1 && visited[i]==0)
{
queue[++rear]=i;
visited[i]=1;
}
}
}
}

/**********************************************************************************
OUTPUT
*********************************************************************************

enter the adjacency matrix: 0


1
1
1
0
0
1
0
0
0
1
1
1
0
0
0
0
1
1
0
0
0
0
0
0
1
0
0
0
0
0
1
1
0
0
0
BFS Traversal is A B C D E F

**********************************************************************************/

You might also like