コード例 #1
0
 public MSTNode recFindNode(MSTNode node, City city)
 {
     if(node == null || node.getCity() == city)
     {
         return node;
     }
     MSTNode toReturn = null;
     foreach(MSTNode curChild in node.getChildren()){
         if (curChild != null)
         {
             toReturn = recFindNode(curChild, city);
         }
     }
     return toReturn;
 }
コード例 #2
0
 public void addChild(MSTNode child) { children.Add(child); }
コード例 #3
0
 public MST(MSTNode inRoot)
 {
     root = inRoot;
 }
コード例 #4
0
        private ArrayList preorderTraversalRecursive(MSTNode curNode, ArrayList path)
        {
            // visit curNode first (because this is preorder)
            path.Add(curNode.getCity());

            // BASE CASE if no children, return path
            if (curNode.getChildren().Count == 0)
            {
                return path;
            }

            // recursively visit each child
            foreach (MSTNode curChild in curNode.getChildren())
            {
                ArrayList subPath = new ArrayList();
                subPath = preorderTraversalRecursive(curChild, subPath);
                for (int i = 0; i < subPath.Count; i++)
                {
                    path.Add(subPath[i]);
                }
            }

            return path;
        }