We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b7b2510 commit ea6f567Copy full SHA for ea6f567
graph-theory/dfs_search.cpp
@@ -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