Exemple #1
0
        /// <summary>
        /// The main method which Inserts a a word in the Trie
        /// </summary>
        private void InsertCore(TrieNode currentNode, int positionInWord, string word)
        {
            if (positionInWord >= word.Length)
            {
                return;
            }

            char     currentChar = word[positionInWord];
            TrieNode node        = null;

            if (!currentNode.Children.ContainsKey(currentChar))
            {
                bool isWord = positionInWord == word.Length - 1 ? true : false;
                node = new TrieNode(currentChar, currentNode, isWord, ignoreCase);
                this.AddNodeToCollection(currentChar, node);
                currentNode.AddChild(node);
            }
            else
            {
                node = currentNode.Children[currentChar];
            }

            this.InsertCore(node, ++positionInWord, word);
        }