示例#1
0
文件: Trie.cs 项目: bitflame/Trie
        /** Inserts a word into the trie. */
        public void Insert(string word)
        {
            TrieNode node = root;

            for (int i = 0; i < word.Length; i++)
            {
                char currentChar = word.ElementAt(i);
                if (!node.ContainsKey(currentChar))
                {
                    node.Put(currentChar, new TrieNode());
                }
                node = node.Get(currentChar);
            }
            node.SetEnd();
        }
示例#2
0
文件: Trie.cs 项目: bitflame/Trie
        private TrieNode SearchPrefix(string word)
        {
            TrieNode node = root;

            for (int i = 0; i < word.Length; i++)
            {
                char curLetter = word.ElementAt(i);
                if (node.ContainsKey(curLetter))
                {
                    node = node.Get(curLetter);
                }
                else
                {
                    return(null);
                }
            }
            return(node);
        }