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); + +}