private bool Remove(string word, Node node) { if (word == "") { if (node.isWord) { node.isWord = false; } return(true); } bool removeFlag = false; char nextChar = word[0]; Node nextNode = null; if (node.HasChild(nextChar)) { if (word.Length > 0) { nextNode = node.GetChild(nextChar); removeFlag = Remove(word.Substring(1), node.GetChild(nextChar)); } } if (removeFlag && !nextNode.HasChildren() && !nextNode.isWord) { node.RemoveChild(nextChar); return(true); } return(false); }
private List <string> AutoComplete(string word, Node node, List <string> results) { if (node.isWord) { results.Add(word); } if (node.HasChildren()) { foreach (var child in node.GetChildren()) { AutoComplete(word + child.value, child, results); } } return(results); }