From 27e155be0c085674c077b7fae7d84f95422869a3 Mon Sep 17 00:00:00 2001 From: Kdev369 <82885255+Kdev369@users.noreply.github.com> Date: Fri, 22 Oct 2021 22:29:18 +0530 Subject: [PATCH] Create iterativeDFS.cpp --- C++ Programs/iterativeDFS.cpp | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 C++ Programs/iterativeDFS.cpp diff --git a/C++ Programs/iterativeDFS.cpp b/C++ Programs/iterativeDFS.cpp new file mode 100644 index 00000000..0efdc047 --- /dev/null +++ b/C++ Programs/iterativeDFS.cpp @@ -0,0 +1,56 @@ +#include +using namespace std; + +vector>graph[1000]; +int visited[1000]; + + +void dfs(int src){ + stack>s; + s.push(make_pair(src,to_string(src)+"")); + + while(s.size()>0){ + auto current = s.top(); + s.pop(); + + if(visited[current.first]==1){ + continue; + } + visited[current.first]=1; + cout<>n>>m; + for(int i=0;i>x>>y>>z; + graph[x].push_back(make_pair(y,z)); + graph[y].push_back(make_pair(x,z)); + + } + int src; + cin>>src; + + +dfs(src); + + + + + + return 0; +}