MCPcopy Create free account
hub / github.com/Seogeurim/CS-study / insert

Method insert

contents/data-structure/code/Trie/TrieExample.java:27–37  ·  view source on GitHub ↗
(String word)

Source from the content-addressed store, hash-verified

25 TrieNode root = new TrieNode();
26
27 void insert(String word) {
28 TrieNode current = root;
29 for (int i = 0; i < word.length(); i++) {
30 char c = word.charAt(i);
31 if (!current.hasChild(c)) {
32 current.children[c - 'a'] = new TrieNode();
33 }
34 current = current.getChild(c);
35 }
36 current.isEnd = true;
37 }
38
39 boolean checkWord(String word) {
40 TrieNode current = root;

Callers 1

mainMethod · 0.95

Calls 2

hasChildMethod · 0.95
getChildMethod · 0.95

Tested by

no test coverage detected