예제 #1
0
 private void SearchForWords(Trie.Node node, string prev, string cur, string rem)
 {
     if (string.IsNullOrEmpty(cur))
     {
         return;
     }
     if (isWord(node, cur))
     {
         if (cur.Length == rem.Length)
         {
             this.Add(prev + " " + cur);
         }
         SearchForWords(node, prev + " " + cur, rem.Substring(cur.Length), rem.Substring(cur.Length));
     }
     SearchForWords(node, prev, cur.Substring(0, cur.Length - 1), rem);
 }
예제 #2
0
        private bool isWord(Trie.Node node, string str)
        {
            const string Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            //var n = 0;

            var curNode = node;

            for (int i = 0; i < str.Length; i++)
            {
                var l = new Letter();
                l.Index = Chars.IndexOf(str[i]);
                if (curNode.Edges.ContainsKey(l))
                {
                    curNode = curNode.Edges[l];
                }
                else
                {
                    return(false);
                }
            }
            return(curNode.IsTerminal);
        }