How can i backtrack when the DFS is implemented using a stack.
pseudo code
void dfs(vertex *root)
{
push root to stack
root visited
while(stack is not empty)
{
vertex *n= top of stack vertex;
vertex *child=unvisited child nodes
if(child!=NULL)
{
// go deeper into the graph
visit child
}
else
{
pop from stack
}
}
}

New Topic/Question
Reply



MultiQuote



|