GetChildNode() public method

public GetChildNode ( char c ) : TrieNode
c char
return TrieNode
Exemplo n.º 1
0
        /// <summary>
        /// Performs the actual recursive lookup of the characters in the item
        /// </summary>
        /// <param name="node">node to search for matches</param>
        /// <param name="item">string to be looked-up</param>
        /// <returns>returns </returns>
        protected TrieNode FindPrefixRecursive(TrieNode node, string item)
        {
            if (String.IsNullOrEmpty(item))
            {
                return(node);
            }
            char     firstChar = item[0];
            TrieNode childNode = node.GetChildNode(firstChar);

            // If there is no corresponding node, then we didn't find our item - return null.
            if (childNode == null)
            {
                return(null);
            }
            else
            {
                // we did find our matching node - go to it and continue matching the rest of the string
                return(FindPrefixRecursive(childNode, item.Substring(1)));
            }
        }
        /// <summary>
        /// Performs the actual recursive lookup of the characters in the item
        /// </summary>
        /// <param name="node">node to search for matches</param>
        /// <param name="item">string to be looked-up</param>
        /// <returns>returns </returns>
        protected TrieNode FindPrefixRecursive(TrieNode node, string item)
        {
            if (String.IsNullOrEmpty(item))
            {
                return node;
            }
            char firstChar = item[0];
            TrieNode childNode = node.GetChildNode(firstChar);

            // If there is no corresponding node, then we didn't find our item - return null.
            if (childNode == null)
            {
                return null;
            }
            else
            {
                // we did find our matching node - go to it and continue matching the rest of the string
                return FindPrefixRecursive(childNode, item.Substring(1));
            }
        }