AddOrGetNode() public method

Adds the requested character to the Node subtree children If there is already a child representing the character - return it
public AddOrGetNode ( char c ) : TrieNode
c char
return TrieNode
 /// <summary>
 /// Performs the actual recursive insertion of the characters in the item into the Trie nodes
 /// </summary>
 /// <param name="node"></param>
 /// <param name="item"></param>
 /// <param name="index"></param>
 protected void AddRecursive(TrieNode node, String item, int index)
 {
     // If we are at and end of word - mark the node as ending a word
     if (item.Length == index)
     {
         node.EndsWord = true;
         return;
     }
     char firstChar = item[index];
     TrieNode childNode = node.AddOrGetNode(firstChar);
     if (childNode != null)
     {
         AddRecursive(childNode, item, index + 1);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Performs the actual recursive insertion of the characters in the item into the Trie nodes
        /// </summary>
        /// <param name="node"></param>
        /// <param name="item"></param>
        /// <param name="index"></param>
        protected void AddRecursive(TrieNode node, String item, int index)
        {
            // If we are at and end of word - mark the node as ending a word
            if (item.Length == index)
            {
                node.EndsWord = true;
                return;
            }
            char     firstChar = item[index];
            TrieNode childNode = node.AddOrGetNode(firstChar);

            if (childNode != null)
            {
                AddRecursive(childNode, item, index + 1);
            }
        }