## Iterative DFS vs Recursive DFS and different elements order

I have written a recursive DFS algorithm to traverse a graph: void Graph<E, N>::DFS(Node n) { std::cout << ReadNode(n) << ” “; MarkVisited(n); NodeList adjnodes = Adjacent(n); NodeList::position pos = adjnodes.FirstPosition(); while(!adjnodes.End(pos)) { Node adj = adjnodes.ReadList(pos); if(!IsMarked(adj)) DFS(adj); pos = adjnodes.NextPosition(pos); } } Then I have written an iterative DFS algorithm using a stack: … Read more