Skip to content

Commit

Permalink
Added DFS in C++ (Asiatik#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
adikul30 authored and tstreamDOTh committed Oct 8, 2018
1 parent 322dc9f commit b872693
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Graphs/DFS/C++/DFS.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* adikul30
* Aditya Kulkarni <[email protected]>
*/
#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for(int i = a; i < b; ++i)
#define pb push_back
#define MAX 100

typedef vector<int> vi;

bool visited[MAX];
vi adj[MAX];

void dfs(int s){
if (visited[s]) return;
visited[s] = true;
cout << s << endl;
for (auto u : adj[s]){
dfs(u);
}
}

int main()
{
ios_base::sync_with_stdio(0);
int n = 5;
REP(i,1,n+1) visited[i] = false;
adj[1].pb(2);
adj[1].pb(3);
adj[1].pb(5);
adj[2].pb(3);
adj[3].pb(4);
dfs(1);

return 0;
}

0 comments on commit b872693

Please sign in to comment.