Exemplo n.º 1
0
 /// <summary>
 /// Registers the parentage of adoptee as this object.
 /// </summary>
 /// <param name="adoptee">The node whose parentage should be set.</param>
 private void RegisterParentage(IBinaryArbor <T> adoptee)
 {
     if (null != adoptee)
     {
         adoptee.Parent = this;
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the children of root as a Depth-First Search (DFS)
        /// </summary>
        /// <returns>The children of root as a Depth-First Search (DFS)</returns>
        /// <param name="root">the root</param>
        private IEnumerable <IBinaryArbor <T> > GetChildrenAsDFSRecursive(IBinaryArbor <T> root)
        {
            List <IBinaryArbor <T> > items = new List <IBinaryArbor <T> >();

            if (null == root)
            {
                //No more items.
                return(items);
            }
            if (null != root.Left)
            {
                items.Add(root.Left);
            }
            if (null != root.Left)
            {
                items.AddRange(GetChildrenAsDFSRecursive(root.Left));
            }
            if (null != root.Right)
            {
                items.Add(root.Right);
            }

            if (null != root.Right)
            {
                items.AddRange(GetChildrenAsDFSRecursive(root.Right));
            }


            return(items);
        }
        public void TestExtractValues()
        {
            IBinaryArbor <char>[] nodes = new IBinaryArbor <char> [4];
            char[] chars = new char[4];
            chars [0] = 'a';
            chars [1] = 'b';
            chars [2] = 'c';
            chars [3] = 'd';
            nodes [0] = new BinaryArbor1 <char> (chars[0], null, null);
            nodes [1] = new BinaryArbor1 <char> (chars[1], null, null);
            nodes [2] = new BinaryArbor1 <char> (chars[2], null, null);
            nodes [3] = new BinaryArbor1 <char> (chars[3], null, null);
            IEnumerable <char> values = BinaryArbor1 <char> .ExtractValues(nodes);

            AssertCollectionEquality(values, chars);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Arbor.BinaryArbor1`1"/> class.
 /// </summary>
 /// <param name="value">The value for this node</param>
 /// <param name="left">The left child of this node (nullable)</param>
 /// <param name="right">The right child of this node (nullable)</param>
 public BinaryArbor1(T value, IBinaryArbor <T> left, IBinaryArbor <T> right)
 {
     Value = value;
     Left  = left;
     Right = right;
 }
Exemplo n.º 5
0
 private IEnumerable <IBinaryArbor <T> > GetChildrenAsBFSRecursive(IBinaryArbor <T> root)
 {
     //stub for now
     return(null);
 }