private void PreTraverse(NodeHashMap node) { Console.WriteLine(node.Value); foreach (var child in node.GetChildren()) { PreTraverse(child); } }
private void FindWords(NodeHashMap node, string prefix, List <string> words) { if (node is null) { return; } if (node.IsEndOfWord) { words.Add(prefix); } foreach (var child in node.GetChildren()) { FindWords(child, prefix + child.Value, words); } }
private void Remove(NodeHashMap node, string word, int index) { if (index == word.Length) { node.IsEndOfWord = false; return; } var ch = word.ElementAt(index); var child = node.GetChild(ch); if (child is null) { return; } Remove(child, word, index + 1); if (!child.HasChildren() && !child.IsEndOfWord) { node.RemoveChild(ch); } }
public TrieWithHashMap() { Root = new NodeHashMap(' '); }