From e2625b98742e284e9b2829d075e50a92d1501364 Mon Sep 17 00:00:00 2001 From: Gargi Kale <86710899+Gargi14@users.noreply.github.com> Date: Sat, 21 Oct 2023 14:39:32 +0530 Subject: [PATCH] BFSDFS.cpp Breadth First Search & Depth First Search Program in cpp --- Programs in different languages/bfsdfs.cpp | 152 +++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 Programs in different languages/bfsdfs.cpp diff --git a/Programs in different languages/bfsdfs.cpp b/Programs in different languages/bfsdfs.cpp new file mode 100644 index 00000000..23ddcd69 --- /dev/null +++ b/Programs in different languages/bfsdfs.cpp @@ -0,0 +1,152 @@ +#include +#include +#include +using namespace std; + +vector>graph; +vectorvisited; + +void dfs(int v){ + visited[v]=true; + cout<q; + q.push(v); + visited[v]=true; + + while(!q.empty()) + { + int curr=q.front(); + q.pop(); + cout<q; + visited[v]=true; + q.push(v); + + while(!q.empty()) + { + int curr=q.front(); + q.pop(); + + for(int i=0;i>n; + cout<<"Enter number of edges: "; + cin>>m; + + graph.resize(n); + visited.resize(n,false); + + for(int i=0;i>u>>v; + graph[u].push_back(v); + graph[v].push_back(u); + } + + while(true) + { + cout<<"***************************\n"; + cout<<"1.DFS\n"; + cout<<"2.BFS\n"; + cout<<"3.Search\n"; + cout<<"4.Quit\n"; + + int ch; + cout<<"Enter Your Choice\n"; + cin>>ch; + + switch(ch) + { + case 1: + cout<<"DEPTH FIRST SEARCH: "; + for(int i=0;i>x; + int y; + cout<<"SEARCH\n"; + y=bfsSearch(n,0,x); + if(y==0) + { + cout<<"NODE NOT FOUND"; + } + break; + + default: + cout<<"Thank you for using this program!!"; + break; + + } + } + return 0; +} \ No newline at end of file