TreeNode.Flatten C# (CSharp) Method

Flatten() static private method

static private Flatten ( ArrayList ar, TreeNode, nodes ) : void
ar ArrayList
nodes TreeNode,
return void
    static void Flatten(ArrayList ar, TreeNode [] nodes)
    {
        foreach (TreeNode n in nodes) {
            if (n is Tree) {
                // Trees always seem to have nodes
                // included in the xml, so I am not
                // sure if the populaltion is
                // necessary. But let's be safe
                n.PopulateChildrenData ();
                Flatten (ar, n.Children);
            } else
                ar.Add (n);
        }
    }

Usage Example

示例#1
0
        public void Flatten_IntegerTreeNode_EquivalentToExpectedList()
        {
            // Create a tree like the following
            // 1
            // 2 3 5
            // 6 7 4 9 10
            // 11 12 13 14
            // 16 15 17
            var rootNode   = new TreeNode <int>(1);
            var firstLevel = rootNode.AddChildren(2, 3, 5).ToList();

            firstLevel.First().AddChildren(6).First().AddChildren(11, 12).Last().AddChildren(16);
            firstLevel.Skip(1).First().AddChildren(7, 4);
            var node5Children = firstLevel.Skip(2).First().AddChildren(9, 10).ToList();

            node5Children.First().AddChildren(13);
            var node14 = node5Children.Skip(1).First().AddChildren(14).First();

            node14.AddChildren(15, 17);

            var expected = new List <int> {
                1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17
            };
            var actual = rootNode.Flatten().ToList();

            CollectionAssert.AreEquivalent(expected, actual);
        }
All Usage Examples Of TreeNode::Flatten