예제 #1
0
        public static NodeB[] toRecursiveTree(NodeA[] treeA)
        {
            ArrayList treeB = new ArrayList();

            for (int currentIndex = 0; currentIndex < treeA.Length; currentIndex++)
            {
                bool isChild = false;
                for (int i = 0; i < treeA.Length; i++)
                {
                    for (int j = 0; j < treeA[i].getChildren().Length; j++)
                    {
                        //check if id = some nodes child id. if no child is found the current index is at the top of the tree.
                        if (treeA[currentIndex].getId() == treeA[i].getChildren()[j])
                        {
                            isChild = true;
                        }
                    }
                }
                if (!isChild)
                {
                    NodeB child = new NodeB(treeA[currentIndex].getId());
                    child.setChildren(addRecursiveChildren(treeA, treeA[currentIndex]));
                    treeB.Add(child);
                }
            }

            NodeB[] recursiveTree = new NodeB[treeB.Count];
            for (int i = 0; i < treeB.Count; i++)
            {
                recursiveTree[i] = (NodeB)treeB[i];
            }

            return(recursiveTree);
        }
예제 #2
0
        public static NodeB[] addRecursiveChildren(NodeA[] treeA, NodeA parent)
        {
            NodeB[] treeB = new NodeB[parent.getChildren().Length];
            int     index = 0;

            for (int i = 0; i < treeA.Length; i++)
            {
                for (int j = 0; j < parent.getChildren().Length; j++)
                {
                    if (treeA[i].getId() == parent.getChildren()[j])
                    {
                        NodeB child = new NodeB(treeA[i].getId());
                        child.setChildren(addRecursiveChildren(treeA, treeA[i]));
                        treeB[index] = child;
                        index++;
                    }
                }
            }
            return(treeB);
        }