// Inserts a word into the trie. public void Insert(string word) { var children = root.Children; for (int i = 0; i < word.Length; i++) { char c = word[i]; TrieNode t; if (children.ContainsKey(c)) { t = children[c]; } else { t = new TrieNode(c); children.Add(c, t); } children = t.Children; if (i == word.Length - 1) { t.IsLeaf = true; } } }
public PrefixTree() { root = new TrieNode(); }