SEE Practical Exam
- Due No Due Date
- Points 0
- Submitting a file upload
Write missing code for BFS, highlighted with comments.
Give input for given graph.
#include<stdio.h>
#include<conio.h>
//Give input of given graph
int front=-1;
int rear=-1;
//Declare array
int q[10];
void enqueue(int);
int dequeue();
void bfs(int s);
void main()
{
int i,j,s;
clrscr();
printf("\n\n THE ADJACENCY MATRIX IS \n\n");
for(i=0;i<=n-1;i++)
{
for(j=0;j<=n-1;j++)
{
printf(" %d ",a[i][j]);
}
printf("\n");
}
printf("\n\n ENTER THE SOURCE VERTEX : ");
scanf("%d",&s);
printf("\n\n BFS TRAVERSAL IS : ");
bfs(s);
getch();
}
void bfs(int s)
{
int p,i;
enqueue(s);
visit[s]=1;
loop:
p=dequeue();
while(p!=-1)
{
printf(" %d ",p);
for(i=0;i<=n-1;i++)
{
//missing code
}
goto loop;
}
}
void enqueue(int item)
{
if(rear==9)
{
printf("QUEUE FULL");
}
else
{ rear = rear + 1;
q[rear]=item;
//Missing code
}
}
int dequeue()
{
int item;
if((front==-1))
{
return -1;
}
else
{
item = q[front];
if(front == rear)
{
front = -1;
rear = -1;
}
else
{
front = front + 1;
}
return item;
}
}