fork download
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package google;
  7. //import com.sun.org.apache.xml.internal.utils.Trie;
  8. import java.util.*;
  9. /**
  10.  *
  11.  * @author prachichauhan
  12.  */
  13. class trietest {
  14.  
  15. char c;
  16. //chirlder of trie are arrays of tri
  17. Trie[] children;
  18. boolean word;//marks the end of the word
  19. public trietest(){
  20. this.c=0;
  21. this.children=new Trie[26];
  22. this.word=false;//since empty string
  23. }
  24. public void add(String s){
  25. if(s.isEmpty()){
  26. this.word=true; //end of word
  27. return;
  28. }
  29.  
  30. char letter =s.charAt(0);
  31. int index= letter-'a';//to give each letter a correct position in the array; eg. index of b=98-97=1 , which makes sense as b is second chaarcter in the alphabet
  32.  
  33. if(this.children[index]==null){
  34. this.children[index]=new Trie();
  35. }
  36. this.children[index].add(s.substring(1));
  37.  
  38. }
  39.  
  40. public boolean isword(String s){
  41.  
  42. if(s.isEmpty()){
  43. return this.word;
  44. }
  45.  
  46. int index=s.charAt(0)-'a';
  47.  
  48. if(this.children[index]==null){
  49. return false;
  50. }
  51. return this.children[index].isword(s.substring(1));
  52. }
  53. }
  54.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:17: error: cannot find symbol
    Trie[] children;
    ^
  symbol:   class Trie
  location: class trietest
Main.java:21: error: cannot find symbol
        this.children=new Trie[26];
                          ^
  symbol:   class Trie
  location: class trietest
Main.java:34: error: cannot find symbol
            this.children[index]=new Trie();
                                     ^
  symbol:   class Trie
  location: class trietest
3 errors
stdout
Standard output is empty