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