MCPcopy Index your code
hub / github.com/careercup/ctci / addWord

Method addWord

java/CtCILibrary/CtCILibrary/TrieNode.java:49–71  ·  view source on GitHub ↗
(String word)

Source from the content-addressed store, hash-verified

47 * appropriate position in the trie.
48 */
49 public void addWord(String word) {
50 if (word == null || word.isEmpty()) {
51 return;
52 }
53
54 TrieNode child;
55 char firstChar = word.charAt(0);
56
57 TrieNode t = getChild(firstChar);
58
59 if (t == null) {
60 child = new TrieNode(firstChar);
61 children.add(child);
62 } else {
63 child = t;
64 }
65
66 if (word.length() > 1) {
67 child.addWord(word.substring(1));
68 } else {
69 child.setTerminates(true);
70 }
71 }
72
73 /* Find a child node of this node that has the char argument as its
74 * data. Return null if no such child node is present in the trie.

Callers 1

TrieMethod · 0.45

Calls 5

getChildMethod · 0.95
setTerminatesMethod · 0.95
isEmptyMethod · 0.45
addMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected