Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions DFS/cpp/dfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ void dfs(int node)
visited[node] = true;

// For all nodes adjacent to the given node and have not yet been visited, we apply DFS function again.
for(int i=0;i<v[node].size();i++)
{
int u = v[node][i];
if(!visited[u])
{
cout<<u<<" ";
dfs(u);

for(auto neighbour: v[node]){
if( !visited[neighbour]){
cout << neighbour << " ";
dfs(neighbour);
}
}

}
}

int main()
Expand Down