示例#1
0
 private void GetWords(Node node, char[] charstack, int stackdepth, List<string> result)
 {
     if (node == null)
     {
         return;
     }
     if (node.IsEnd)
     {
         result.Add(new string(charstack, 0, stackdepth));
     }
     foreach (Node child in node.Children.Values)
     {
         charstack[stackdepth] = child.Letter;
         GetWords(child, charstack, stackdepth + 1, result);
     }
 }
示例#2
0
 public Trie()
 {
     Root = new Node((char)0);
 }
示例#3
0
        public void Insert(String word)
        {
            Node current = Root;
            int wdepth = 1;
            for (int level = 0; level < word.Length; level++)
            {
                Dictionary<char, Node> children = current.Children;
                char ch = word[level];

                if (children.ContainsKey(ch))
                    current = children[ch];
                else
                {
                    Node temp = new Node(ch);
                    children.Add(ch, temp);
                    current = temp;
                }
                wdepth++;
            }
            if (wdepth > Depth)
            {
                Depth = wdepth;
            }

            current.IsEnd = true;
        }