I have a DFS search and now I am trying to implement Iterative deepening search with this DFS but I really do not understand what should I do. I have tried many ways but finally I found It was wrong! Do you have any suggestion that what changes should I do?
public void dfs()
{
Stack s=new Stack();
s.push(this.rootNode);
rootNode.visited=true;
printNode(rootNode);
while(!s.isEmpty())
{
Node n=(Node)s.peek();
Node child=getUnvisitedChildNode(n);
if(child!=null)
{
child.visited=true;
printNode(child);
s.push(child);
}
else
{
s.pop();
}
}
clearNodes();
}