So the question is
Write an Iterator that will perform a depth first search on any N-ary Tree.
We just started reading about trees so I'm not overly familiar with them. I understand the basic concepts of them. So my question is, does this require writing an iterator class or is it possible to do with a single algorithm? I found this online:
Code:public void DfsIterative(Node node) { var trail = new Stack<Transition>(); DoSomethingWithNode(node); PushAllTransitionsToStack(node, trail); while(trail.Count>0) { Transition t = trail.Pop(); Node destination = t.Destination; DoSomethingWithNode(destination); PushAllTransitionsToStack(destination, trail); } }
This is labeled as classical iterative version of DFS. I don't understand how that iterates.



LinkBack URL
About LinkBacks


