Пример #1
0
    public void AddWord(TrieNode root, string word, int index)
    {
        for (int i = word.Length - 1; i >= 0; i--)
        {
            int nextIdx = word[i] - 'a';

            if (root.Next[nextIdx] == null)
            {
                root.Next[nextIdx] = new TrieNode();
            }

            if (IsPalindrome(word, 0, i))
            {
                root.AddPalindromeIndex(index);
            }

            root = root.Next[nextIdx];
        }

        root.AddPalindromeIndex(index);
        root.SetIndex(index);
    }