I am attempting to implement a very simple Trie in Java that supports 3 operations. I\'d like it to have an insert method, a has method (ie is a certain word in the trie),
Here is my implementation: -
public class Tries {
class Node {
HashMap children;
boolean end;
public Node(boolean b){
children = new HashMap();
end = false;
}
}
private Node root;
public Tries(){
root = new Node(false);
}
public static void main(String args[]){
Tries tr = new Tries();
tr.add("dog");
tr.add("doggy");
System.out.println(tr.search("dogg"));
System.out.println(tr.search("doggy"));
}
private boolean search(String word) {
Node crawl = root;
int n = word.length();
for(int i=0;i