I have conflicting information about depth first traversal and could use some help in understanding how to build a program. Given a certain graph, I want to print a sequence of vertices. The user will input a particular node to start the traversal from. I am looking at different examples and I don't understand how the order of the depth-first traversal works. I have the following pseudocode to work with:
public DFS() {
DFS(v)
{ num(v) = i ++;
for all vertices u adjacent to v
{ if num(u) is 0
attach edge(uv) to edges;
DFS(u);
}
}
depthFirstSearch()
{ for all vertices v
num(v) = 0;
edges = null; //vector of all edges
i=1;
while there is a vertex v such that num(v) is 0
DFS(v);
output edges;
}