为什么我的 Trie 搜索方法在 Java 中总是返回 true?

问题描述

所以我正在做一个项目,它读取一个文本文件并将该文件的数据插入到 Trie 中。用户输入一个字符串进行搜索,如果trie 包含单词,它将显示单词。我对 Trie 做了插入部分,但是当我尝试运行搜索方法时,所有数据都返回 true。当用户输入一个字符串时,它会像没有比较一样打印所有数据。你们能帮我吗?

   public static boolean searchInTrie(String key){

   TrieNode current = root;
   
    for (int i = 0; i < key.length(); i++) {
        char c = key.charat(i);
        int index= c - 'A';
        
        if (current.children[index]==null) 
            return false; 
       
        current= current.children[index];
    }

   return (current!=null)&&(current.isWord=true);
}

这是主要的

     for (String word : wordsArrayList) {
        System.out.println(searchInTrie(wordToSearch));
        searchInTrie(wordToSearch);
        if (searchInTrie(wordToSearch)==true) {
            System.out.println(word);
        }
    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)