BFS - printf("\n ENTER THE NUMBER OF NODES\n");

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

View Full Document Right Arrow Icon
#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++) { q[++last]=i; visited[i]=1; } }} void main() { int i,j,m,n; int adj[MAX][MAX]; clrscr();
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
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

This note was uploaded on 10/25/2010 for the course CMPN SEM4 taught by Professor Thakur during the Spring '07 term at University of Mumbai.

Page1 / 2

BFS - printf("\n ENTER THE NUMBER OF NODES\n");

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online