Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将此递归深度优先搜索转换为深度受限搜索?_Java_Graph_Depth First Search - Fatal编程技术网

Java 如何将此递归深度优先搜索转换为深度受限搜索?

Java 如何将此递归深度优先搜索转换为深度受限搜索?,java,graph,depth-first-search,Java,Graph,Depth First Search,我一直在尝试将深度优先搜索改为深度受限搜索,但到目前为止我还没有找到一种方法。有什么想法吗 // 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 a

我一直在尝试将深度优先搜索改为深度受限搜索,但到目前为止我还没有找到一种方法。有什么想法吗

        // 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); 
} 
//DFS使用的函数
void DFSUtil(int v,布尔值[])
{ 
//将当前节点标记为已访问并打印
访问[v]=正确;
系统输出打印(v+“”);
//对与该顶点相邻的所有顶点重复
迭代器i=adj[v].listIterator();
while(i.hasNext())
{ 
int n=i.next();
如果(!已访问[n])
DFSUtil(n,已访问);
} 
} 
//执行DFS遍历的函数。它使用递归DFSUtil()
无效DFS(整数v)
{ 
//将所有顶点标记为未访问(设置为
//在java中默认为false)
布尔值[]=新布尔值[V];
//调用递归助手函数以打印DFS遍历
DFSUtil(v,访问);
} 

如果我没有弄错,您希望搜索到限制,那么您可以使用计数器,并使用限制值与
DFSUtil
函数中的限制进行比较

请定义“深度限制搜索”。请张贴包含测试数据的最终预期结果“搜索到极限”什么极限?