Menu
 

bfs is one the most importat algorith techniques in the academics of btech allover india  and abroad;


we provide you the code here:


pls share with your frnds and feel free to request us more programs at prakashmishra338@gmail.com


#include<stdio.h>

#define MAXSIZE 10

int q[10],visit[10],n;

int rear=0;

int front=0;

void bfs(int,int[][10]);

int enqueue(int V)


if(rear==MAXSIZE)

printf(“queue overflow”);

else

q[++rear]=V;


int dequeue()


int t;

if(rear==front)

return(0);

else


t=q[++front];

return(t);




void bfs(int v,int a[][10])


int i,p,s;

printf(“enter the source node”);

scanf(“%d”,&s);

for(i=1;i<=n;i++)


visit[i]=0;

//enqueue(v);

visit[s]=1;

p=s;

while(p!=0)


printf(“%d->”,p);

for(i=1;i<=n;i++)


if((a[p][i]!=0)&&(visit[i]!=1))


enqueue(i);

visit[i]=1;



p=dequeue();



int main()


FILE *fp;

int i,a[10][10],j;

fp=fopen(“adjacency”,”r”);

if(fp==NULL)


printf(“file not opened”);

return 1;


fscanf(fp,”%d”,&n);

for(i=1;i<=n;i++)


for(j=1;j<=n;j++)


fscanf(fp,”%d”,&a[i][j]);

printf(“%d”,a[i][j]);


printf(“\n”);


bfs(1,a);

fclose(fp);

return (0);



BFS program implementation with c

Post a Comment

 
Top