From ac52df571231b6a0e7480419ab2c1b57807c5e31 Mon Sep 17 00:00:00 2001 From: IshikaOG <115558488+IshikaOG@users.noreply.github.com> Date: Tue, 11 Oct 2022 19:17:53 +0530 Subject: [PATCH] added BFS --- BFS.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 BFS.cpp diff --git a/BFS.cpp b/BFS.cpp new file mode 100644 index 0000000..6b9d5a8 --- /dev/null +++ b/BFS.cpp @@ -0,0 +1,45 @@ +#include +using namespace std; + +void bfs(vector> &adjList,int source,int N){ + vector visited(N,false); + + queue q; + visited[source]=true; + q.push(source); + + while(!q.empty()){ + int currentNode=q.front(); + cout<<"Visited: "<> adjList(N); + + adjList[0].push_back(1); + adjList[0].push_back(2); + adjList[0].push_back(4); + + adjList[1].push_back(3); + adjList[2].push_back(3); + adjList[3].push_back(4); + adjList[3].push_back(5); + + bfs(adjList,0,N); + +}