Skip to content

Commit

Permalink
Update graph.c
Browse files Browse the repository at this point in the history
  • Loading branch information
adhilsalim committed Feb 21, 2023
1 parent b0baba7 commit 783bdfe
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion Graph/graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,32 @@ void DFS(int v)

void BFS(int v)
{
VISIT[v] = 1;
enQueue(v);

while (REAR != -1 && FRONT != -1)
{
int popped_vertex;
popped_vertex = deQueue();

for (int i = 0; i < VERTEX; i++)
{
if (GRAPH[popped_vertex][i] == 1 && VISIT[i] == 0)
{
VISIT[i] = 1;
enQueue(i);
}
}
}

for (int i = 0; i < VERTEX; i++)
{
if (VISIT[i] == 0)
{
BFS(i);
break;
}
}
}

void enQueue(int element)
Expand Down Expand Up @@ -157,5 +183,5 @@ void main()
}

printf("\nBFS: ");
// BFS(start_vertex);
BFS(start_vertex);
}

0 comments on commit 783bdfe

Please sign in to comment.