public void AddWord(string word) { if (String.IsNullOrEmpty(word)) { isLeaf = true; return; } if (children == null) { children = new Hashtable(); } SimpleTrie child = null; if (!children.ContainsKey(word[0])) { child = new SimpleTrie(word.Length == 1); children.Add(word[0], child); } child = (SimpleTrie)children[word[0]]; child.AddWord(word.Substring(1)); }
public DailyCodingProblem10062018() { string[] words = { "mantel", "piece", "shelf", "air", "airborne", "born", "this", "is", "a", "add", "addon", "on", "quick", "brown", "the", "fox", "bed", "bath", "bedbath", "beyond", "quicker", "aftereffect", "afternoon", "afterthought", "airbag", "anybody", "how", "any", "anyhow", "anywho", "ever", "however" }; trie = new SimpleTrie(); foreach (string word in words) { trie.AddWord(word); } }