private TrieNode Contains(char c, TrieNode node)
 {
     if (node.Contains(c))
     {
         return(node.GetChild(c));
     }
     else
     {
         return(null);
     }
 }
 private TrieNode Insert(char c, TrieNode node)
 {
     if (node.Contains(c))
     {
         return(node.GetChild(c));
     }
     else
     {
         int n = c - 'a';
         return(node.nodes[n] = new TrieNode());
     }
 }
Beispiel #3
0
            public void insert(string word)
            {
                TrieNode cur = root;

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

                    if (cur.GetChild(c) != null)
                    {
                        cur = cur.GetChild(c);
                    }
                    else
                    {
                        TrieNode temp = new TrieNode(c);
                        cur.trieNodes.Add(c, temp);
                        cur = temp;
                    }
                }

                cur.isEnd = true;
            }
 private TrieNode Insert(char c, TrieNode node)
 {
     if (node.Contains(c))
         return node.GetChild(c);
     else
     {
         int n = c - 'a';
         return node.nodes[n] = new TrieNode();
     }
 }
 private TrieNode Contains(char c, TrieNode node)
 {
     if (node.Contains(c))
         return node.GetChild(c);
     else
         return null;
 }