Пример #1
0
 private static void GetLocations(List<int[]> loc1, List<List<int[]>> locs, TreeNode curr)
 {
     loc1.Add(curr.Location);
     if (curr.IsLeaf) locs.Add(loc1);
     else {
         int i = 0;
         List<List<int[]>> clonedlists = new List<List<int[]>>();
         for (int j = 0; j < curr.NumChildren-1; j++){
             List<int[]> l = new List<int[]>();
             foreach (int[] coords in loc1) l.Add(coords);
             clonedlists.Add(l);
         }
         foreach (var treeNode in curr.Children) {
             List<int[]> list;
             if (i == 0) list = loc1;
             else list = clonedlists[i - 1];
             GetLocations(list, locs, treeNode);
             i++;
         }
     }
 }
Пример #2
0
 private Tree MakeTree(int[] location, string firstletter, string val)
 {
     //create a tree
     var tree = new Tree();
     //set the head of the tree to take the location of this copy of the first letter of the word
     var head = new TreeNode(location, firstletter);
     tree.Head = head;
     string remainingletters;
     GetFirstLetter(val, out remainingletters);
     //setup the trees branches with the tree, and all but the first letter of the string
     ConstructBranches(remainingletters, head);
     return tree;
 }
Пример #3
0
 private void ConstructBranches(string val, TreeNode currentnode)
 {
     if (val.Length == 0) return;
     string remainder;
     var first = GetFirstLetter(val, out remainder);
     foreach (var cell in locations_[first]) {
         if (NextTo(currentnode.Location, cell)) {
             //if the location of the current node is adjactent to a location for the next letter
             // add a child node to the tree with that location
             var node = new TreeNode(currentnode, cell, first);
             //then proceed through to the next letter
             ConstructBranches(remainder, node);
         }
     }
 }
Пример #4
0
 public TreeNode(TreeNode parent, int[] location, string val)
     : this(location, val)
 {
     Parent = parent;
 }