[英]How can i convert this recursive depth first search into a depth limited search?
I've been trying to change this depth first search into a depth limited search but so far i haven't been able to figure out a way to do so.我一直在尝试将这种深度优先搜索更改为深度有限搜索,但到目前为止我还没有找到一种方法来做到这一点。 any ideas?
有任何想法吗?
// A function used by DFS
void DFSUtil(int v,boolean visited[])
{
// Mark the current node as visited and print it
visited[v] = true;
System.out.print(v+" ");
// Recur for all the vertices adjacent to this vertex
Iterator<Integer> i = adj[v].listIterator();
while (i.hasNext())
{
int n = i.next();
if (!visited[n])
DFSUtil(n, visited);
}
}
// The function to do DFS traversal. It uses recursive DFSUtil()
void DFS(int v)
{
// Mark all the vertices as not visited(set as
// false by default in java)
boolean visited[] = new boolean[V];
// Call the recursive helper function to print DFS traversal
DFSUtil(v, visited);
}
如果我DFSUtil
正确,您想搜索到限制,那么您可以使用计数器并将DFSUtil
函数中的限制与限制值进行比较。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.