previous | start | next

Trie put Method

public void put(String key, V val) {
  root = put(root, key, val, 0);
}

private Node<V> put(Node<V> x, String key, V val, int d) {
  if (x == null) x = new Node<V>();
  if (d == key.length()) {
    x.val = val;
    return x;
  }
  char c = key.charAt(d);
  x.next[c] = put(x.next[c], key, val, d+1);
  return x;
}


previous | start | next