Example #1
0
 public void AddWord(string word)
 {
     char[] chars = word.ToCharArray();
     Node currentNode = _root;
     Node child = null;
     for (int counter = 0; counter < chars.Length; counter++)
     {
         child = currentNode.GetChild(word[counter]);
         if(child == null)
         {
             var newNode = new Node(word[counter]);
             currentNode.Subtree.Add(newNode);
             currentNode = newNode;
         }
         else
             currentNode = child;
         if(counter == chars.Length - 1)
             currentNode.AWordEndsHere = true;
     }
 }
Example #2
0
 public Tree()
 {
     _root = new Node(' ');
     subsequentStrings = new List<string>();
 }
Example #3
0
        private void GenerateSubsequentStrings( Node node,
                                                        string subsequentString)
        {
            if(node == null)
                return;

            subsequentString = subsequentString + node.Char;

            if(node.AWordEndsHere)
            {
                subsequentStrings.Add(subsequentString);
                //return;
            }

            foreach (var subnode in node.Subtree)
                GenerateSubsequentStrings(subnode, subsequentString);
        }