#include #define MAX 10 class DFS { private : int n; int adj[MAX][MAX]; int visited[MAX]; public : void dfs(int); void readmatrix(); }; void DFS :: readmatrix() { int i,j; cout << "\nEnter the number of Vertices in the Graph : "; cin >> n; cout << "\nEnter the Adjacency Matrix\n\n"; for (i = 1; i <= n; i++) for (j = 1; j<= n; j++) cin >> adj[i][j]; for (i = 1; i <= n; i++) visited[i] = 0; } void DFS :: dfs(int source) { int i; visited[source] = 1; cout << source << " "; for (i = 1; i <= n; i++) if (adj[source][i] && !visited[i]) dfs(i); } int main() { int source; DFS depth; depth.readmatrix(); cout << "\nEnter the Source : "; cin >> source; cout << "\nThe nodes visited in the DFS order is : "; depth.dfs(source); return 0; }