예제 #1
0
        public void Addstring(string s)
        {
            Trie_Node n = m_root;

            foreach (char c in s)
            {
                n = n.AddOrGetChild(c);
            }
            n = n.AddOrGetChild('\0');
        }
예제 #2
0
        /*************************************************************
        * Function: search(string input_prefix_string, List<string> words)
        * Date Created: April 23, 2017
        * Date Last Modified: April 23, 2017
        * Description: search the input word.
        * Return: NONE
        *************************************************************/
        public void search(string input_prefix_string, List <string> words)
        {
            if ((string.IsNullOrEmpty(input_prefix_string)))
            {
                return;
            }

            char[] input_prefix_char = input_prefix_string.ToArray();

            Trie_Node cur   = Trie.m_root;
            Trie_Node child = null;

            foreach (char c in input_prefix_char)
            {
                if (cur.children.Exists(x => x.c == c))
                {
                    child = cur.AddOrGetChild(c);
                    cur   = child;
                }
                else
                {
                    words.Add("can't find the word");
                    return;
                }
            }
            //words.Add("success");

            insertString_rec(cur, input_prefix_string.Substring(0, input_prefix_string.Length - 1), words);
        }