MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / dfs

Function dfs

CPP/BFS_AND_DFS.cpp:50–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48
49
50void dfs(int n, vector<int> adj[])
51{
52 vector<bool> visit(v,false);
53 stack<int> s;
54 s.push(n);
55 visit[n]=true;
56 while(!s.empty())
57 {
58 n=s.top();
59 cout<<n<<" ";
60 s.pop();
61 for(int i=0;i<adj[n].size();i++)
62 {
63 if(!visit[adj[n][i]])
64 {
65 s.push(adj[n][i]);
66 visit[adj[n][i]]=true;
67 }
68 }
69 }
70
71}
72
73int main()
74{

Callers 1

mainFunction · 0.70

Calls 4

topMethod · 0.80
pushMethod · 0.45
popMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected