예제 #1
0
        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);
        }
예제 #2
0
 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);
     }
 }
예제 #3
0
 public Tri()
 {
     content = new TriNode();
 }