Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhaveshmunot1/4e6f965b5e2f2f4436e7b08e2b19e613 to your computer and use it in GitHub Desktop.
Save bhaveshmunot1/4e6f965b5e2f2f4436e7b08e2b19e613 to your computer and use it in GitHub Desktop.
Print Depth First Traversal using recursion.
void print_depth_first_traversal(GraphNode *node) {
if (is_visited(node)) {
return;
}
mark_visited(node);
for (GraphNode *neighbor : node->neighbors) {
print_depth_first_traversal(neighbor);
}
print(node->value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment