Пример #1
0
        public void Insert(string word)
        {
            TrieNodeWithUpperCaseLetters current = root;

            for (int i = 0; i < word.Length; i++)
            {
                if (char.IsLower(word[i]))
                {
                    continue;
                }

                if (current.trieNodes[word[i] - 'A'] == null)
                {
                    current.trieNodes[word[i] - 'A'] = new TrieNodeWithUpperCaseLetters();
                }

                current = current.trieNodes[word[i] - 'A'];
            }

            if (!current.words.Contains(word))
            {
                current.words.Add(word);
            }
            current.isLeaf = true;
        }
Пример #2
0
        public TrieNodeWithUpperCaseLetters GetPrefixNode(string word)
        {
            TrieNodeWithUpperCaseLetters current = root;

            for (int i = 0; i < word.Length; i++)
            {
                if (current.trieNodes[word[i] - 'A'] == null)
                {
                    return(null);
                }

                current = current.trieNodes[word[i] - 'A'];
            }
            return(current);
        }
Пример #3
0
 public TrieWithUpperCaseLetters()
 {
     root = new TrieNodeWithUpperCaseLetters();
 }