private bool DeleteWord(string word, int position, TriNode node) { if (position == word.Length) { if (node._isEndOFWord == true) { node._isEndOFWord = false; if (node._data.Count == 0) { return(true); } else { return(false); } } } if (node._data.ContainsKey(word[position])) { var result = DeleteWord(word, position + 1, node._data[word[position]]); if (result && node._data.Count == 1) { node._data.Remove(word[position]); return(true); } } return(false); }
private void PrefixSearchHelper(string inp, TriNode node, List <string> result) { if (node._isEndOFWord) { result.Add(inp); } foreach (var item in node._data) { PrefixSearchHelper(inp + Convert.ToString(item.Key), item.Value, result); } }
public Tri() { content = new TriNode(); }