Пример #1
0
    void insertWord(String word) {
      if (terminal) {
        return;
      }
      if (word.equals("")) {
        if (depth >= 4) {
          terminal = true;
        }
        return;
      }
      if (!children.containsKey(word.charAt(0))) {
        Node newNode = new Node(word.charAt(0), depth + 1);
        addChild(word.charAt(0), newNode);
        newNode.insertWord(word.substring(1));
      } else {
        children.get(word.charAt(0)).insertWord(word.substring(1));
      }

      maxDepth = (maxDepth > depth + word.length()) ? maxDepth : depth + word.length();
    }
Пример #2
0
 private void insertWord(String word) {
   root.insertWord(word);
 }