diff --git a/codes/bfs.cpp b/codes/bfs.cpp new file mode 100644 index 0000000..513ed10 --- /dev/null +++ b/codes/bfs.cpp @@ -0,0 +1,60 @@ +#include +using namespace std; +typedef long long ll; + +vectorv[100007]; +int visited[100007]; +int main(){ + int n,m; + cout<<"Enter the number of vertices and edges: \n"; + cin>>n>>m; + + cout<<"Enter the edges of the graph or tree \n"; + for(int i=0;i>x>>y; + v[x].push_back(y); + v[y].push_back(x); + } + + int src; + cout<<"Enter the source vertex: \n"; + cin>>src; + + queuebfs; + bfs.push(src); + + cout<<"BFS TRAVERSAL: \n"; + while(!bfs.empty()){ + int temp=bfs.front(); + cout<