Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/12.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 递归方法中for循环遇到返回语句 public void delete(字符串键){ 根=删除(根,键,0); } 公共节点删除(节点x,字符串键,int d){ 如果(x==null) 返回null; 如果(d==key.length()) x、 val=null; 否则{ 字符c=键字符(d); x、 next[c]=删除(x.next[c],键,d+1); } //---------------- 如果(x.val!=null) 返回x; 对于(char c=0;c< r;C++){ 如果(x.next[c]!=null) 返回x; 返回null; } }_Java_Algorithm_Dictionary_Trie - Fatal编程技术网

Java 递归方法中for循环遇到返回语句 public void delete(字符串键){ 根=删除(根,键,0); } 公共节点删除(节点x,字符串键,int d){ 如果(x==null) 返回null; 如果(d==key.length()) x、 val=null; 否则{ 字符c=键字符(d); x、 next[c]=删除(x.next[c],键,d+1); } //---------------- 如果(x.val!=null) 返回x; 对于(char c=0;c< r;C++){ 如果(x.next[c]!=null) 返回x; 返回null; } }

Java 递归方法中for循环遇到返回语句 public void delete(字符串键){ 根=删除(根,键,0); } 公共节点删除(节点x,字符串键,int d){ 如果(x==null) 返回null; 如果(d==key.length()) x、 val=null; 否则{ 字符c=键字符(d); x、 next[c]=删除(x.next[c],键,d+1); } //---------------- 如果(x.val!=null) 返回x; 对于(char c=0;c< r;C++){ 如果(x.next[c]!=null) 返回x; 返回null; } },java,algorithm,dictionary,trie,Java,Algorithm,Dictionary,Trie,摘自Algoritm 4一书,TrieST.java 发生了什么事for循环可以多次返回x;返回类型方法可以吗?如果可以,那么最终返回值是多少?调用“return”后,函数终止 因此,函数返回的值为: 如果x.val!=空的 如果对于第一个c(即c=0),x.next[c]=空的 否则无效 正如评论中所说,我想一定是打字错误 public void delete(String key) { root = delete(root, key, 0); } public Node del

摘自Algoritm 4一书,TrieST.java

发生了什么事
for
循环可以多次返回
x
;返回类型方法可以吗?如果可以,那么最终返回值是多少?

调用“return”后,函数终止

因此,函数返回的值为:

  • 如果x.val!=空的
  • 如果对于第一个c(即c=0),x.next[c]=空的
  • 否则无效
正如评论中所说,我想一定是打字错误

public void delete(String key) {
    root = delete(root, key, 0);
}

public Node delete(Node x, String key, int d) {
    if(x == null) 
        return null;
    if(d == key.length())
        x.val = null;
    else {
        char c = key.charAt(d);
        x.next[c] = delete(x.next[c], key, d + 1);
    }

    //----------------
    if(x.val !=null ) 
        return x;
    for (char c = 0;c < R ; c++ ) {
        if(x.next[c] != null)
            return x;
        return null;
    }
}
应该在for循环之后。然后函数将返回:

  • 如果x.val!=空的
  • 如果存在一个c,那么x.next[c]=空的
  • 否则无效
调用“return”后,函数终止

因此,函数返回的值为:

  • 如果x.val!=空的
  • 如果对于第一个c(即c=0),x.next[c]=空的
  • 否则无效
正如评论中所说,我想一定是打字错误

public void delete(String key) {
    root = delete(root, key, 0);
}

public Node delete(Node x, String key, int d) {
    if(x == null) 
        return null;
    if(d == key.length())
        x.val = null;
    else {
        char c = key.charAt(d);
        x.next[c] = delete(x.next[c], key, d + 1);
    }

    //----------------
    if(x.val !=null ) 
        return x;
    for (char c = 0;c < R ; c++ ) {
        if(x.next[c] != null)
            return x;
        return null;
    }
}
应该在for循环之后。然后函数将返回:

  • 如果x.val!=空的
  • 如果存在一个c,那么x.next[c]=空的
  • 否则无效

这看起来像是打字错误。如果for循环总是在第一次迭代中返回,那么就不需要循环了。输入错误是什么意思?打字?这看起来像是打字错误。如果for循环总是在第一次迭代中返回,那么就不需要循环了。输入错误是什么意思?类型?