public void AddWord(string origWord) { char firstChar = origWord[0]; byte firstDigit; if (! WordTree.LetterToDigit.TryGetValue(firstChar, out firstDigit)) { return; } if (! children.ContainsKey(firstDigit)) { children[firstDigit] = new WordTreeNode(); } children[firstDigit].addWordImpl(origWord, origWord.Substring(1)); }
public void AddWord(string origWord) { char firstChar = origWord[0]; byte firstDigit; if (!WordTree.LetterToDigit.TryGetValue(firstChar, out firstDigit)) { return; } if (!children.ContainsKey(firstDigit)) { children[firstDigit] = new WordTreeNode(); } children[firstDigit].addWordImpl(origWord, origWord.Substring(1)); }
public IEnumerable <string> GetAllWords() { Stack <WordTreeNode> nodes = new Stack <WordTreeNode>(); // Depth first nodes.Push(RootNode); while (nodes.Count() > 0) { WordTreeNode node = nodes.Pop(); foreach (string word in node.GetWords()) { yield return(word); } foreach (WordTreeNode child in node.GetChildren()) { nodes.Push(child); } } }
private void addWordImpl(string origWord, string partialWord) { if (partialWord == String.Empty) { this.words.Add(origWord); return; } char nextChar = partialWord[0]; byte nextDigit; if (!WordTree.LetterToDigit.TryGetValue(nextChar, out nextDigit)) { return; } if (!children.ContainsKey(nextDigit)) { children[nextDigit] = new WordTreeNode(); } children[nextDigit].addWordImpl(origWord, partialWord.Substring(1)); }
private void addWordImpl(string origWord, string partialWord) { if (partialWord == String.Empty) { this.words.Add(origWord); return; } char nextChar = partialWord[0]; byte nextDigit; if (! WordTree.LetterToDigit.TryGetValue(nextChar, out nextDigit)) { return; } if (! children.ContainsKey(nextDigit)) { children[nextDigit] = new WordTreeNode(); } children[nextDigit].addWordImpl(origWord, partialWord.Substring(1)); }
public WordTree() { rootNode = new WordTreeNode(); }