コード例 #1
0
        // Inserts a word into the trie.
        public void InsertWord(string word)
        {
            var children = _root.Children;

            for (int i = 0; i < word.Length; i++)
            {
                char    c = word[i];
                TriNode t;

                if (children.ContainsKey(c))
                {
                    t = children[c];
                }
                else
                {
                    t = new TriNode(c);
                    children.Add(c, t);
                }

                children = t.Children;

                if (i == word.Length - 1)
                {
                    t.IsLeaf = true;
                }
            }
        }
コード例 #2
0
        // Returns if the word is in the trie.
        public bool SearchWord(string word)
        {
            Dictionary <char, TriNode> children = _root.Children;
            TriNode triNode = null;

            foreach (var c in word)
            {
                if (children.ContainsKey(c))
                {
                    triNode  = children[c];
                    children = triNode.Children;
                }
                else
                {
                    triNode = null;
                    break;
                }
            }

            return(triNode != null && triNode.IsLeaf);
        }
コード例 #3
0
        // Inserts a word into the trie.
        public void InsertWord(string word)
        {
            var children = _root.Children;
            for (int i = 0; i < word.Length; i++)
            {
                char c = word[i];
                TriNode t;

                if (children.ContainsKey(c))
                    t = children[c];
                else
                {
                    t = new TriNode(c);
                    children.Add(c,t);
                }

                children = t.Children;

                if (i == word.Length - 1)
                      t.IsLeaf = true;
            }
        }
コード例 #4
0
 public Tri()
 {
     _root = new TriNode();
 }
コード例 #5
0
 public Tri()
 {
     _root = new TriNode();
 }