{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# BFS - printf"\n ENTER THE NUMBER OF NODES\n"...

This preview shows pages 1–2. Sign up to view the full content.

#include<stdio.h> #include<conio.h> #define MAX 5 /* RISHI AGARWAL             DFS TRAVERSAL    ROLL NO 02   SE CMPN A*/ void bfs(int adj[MAX][MAX], int start) { int i; int visited[MAX]={0}; int q[30],first = -1,last= -1; visited[start]=1; q[++last]=start; while(first!=last) { start=q[++first]; printf("\t%c",start+65); for( i=0; i<MAX; i++) if(adj[start][i]!=0 && visited[i]==0) { q[++last]=i; visited[i]=1; } }} void main() { int i,j,m,n; int adj[MAX][MAX]; clrscr();

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: printf("\n ENTER THE NUMBER OF NODES\n"); scanf("%d",&n); printf("\n ENTER THE ELEMENTS\n"); for(i=0;i<n;i++) { for(j=0;j<n;j++) { scanf("%d", & adj[i][j]); }} printf("\n\n\t BREADTH FIRST SEARCH TRAVERSAL\n"); bfs(adj,0); getch(); } /*OUTPUT: ENTER THE NUMBER OF NODES 4 ENTER THE ELEMENTS 1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1 BREADTH FIRST SEARCH TRAVERSAL A D E B C */...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern