Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.