public boolean addWord(String word){
  if (word.length() == 0)   return false;
  if (hasWord(word))   return false;
  Node n=root;
  int pos=0;
  while (pos < word.length() && n != null) {
    char k=word.charAt(pos);
    boolean found=false;
    for (    Node fils : n.children) {
      if (fils.c == k) {
        found=true;
        n=fils;
        pos++;
      }
    }
    if (!found) {
      break;
    }
  }
  for (int j=pos; j < word.length(); j++) {
    Node u=new Node(word.charAt(j));
    n.addChild(u);
    n=u;
  }
  n.addChild(new Node('*'));
  numNodes+=(word.length() - pos + 1);
  return true;
}

public boolean addWord ( String word ) { if ( word . length ( ) == 0 ) return false ; if ( hasWord ( word ) ) return false ; Node n = root ; int pos = 0 ; while ( pos < word . length ( ) && n != null ) { char k = word . charAt ( pos ) ; boolean found = false ; for ( Node fils : n . children ) { if ( fils . c == k ) { found = true ; n = fils ; pos ++ ; } } if ( ! found ) { break ; } } for ( int j = pos ; j < word . length ( ) ; j ++ ) { Node u = new Node ( word . charAt ( j ) ) ; n . addChild ( u ) ; n = u ; } n . addChild ( new Node ( '*' ) ) ; numNodes += ( word . length ( ) - pos + 1 ) ; return true ; }
adds a word to the lexicon .
