Skip to content

Commit ea6f567

Browse files
committed
Initial Commit
1 parent b7b2510 commit ea6f567

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

graph-theory/dfs_search.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
***************************
3+
* *
4+
* Author: Swaraj Deep *
5+
* *
6+
***************************
7+
*/
8+
9+
#include <iostream>
10+
#include <vector>
11+
12+
using namespace std;
13+
14+
// Function to make a dfs search to the passed graph
15+
void dfs_search(vector<vector<int>> &graph, int vertex, vector<bool> &visited)
16+
{
17+
visited[vertex] = true; // Mark the current vertex as visited
18+
cout << vertex << ' '; // Print the current vertex
19+
for (int u : graph[vertex]) // Iterate over each of the connected vertex of the given vertex
20+
{
21+
if (!visited[u]) // Check if the vertex is visited or not
22+
{
23+
dfs_search(graph, u, visited); // Make a dfs call if the current vertex is not visited
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)