예제 #1
0
        /// <summary>
        /// Attaches a LinkedBinaryTrees to the left or the right of a node
        /// </summary>
        /// <param name="Node"></param>
        /// <param name="Left"></param>
        /// <param name="Right"></param>
        public void Attach(Position Node, LinkedBinaryTree <T> Subtree, bool left = true)
        {
            Node node = validate(Node);

            if ((node.left != null && left == true) || (node.right != null && left == false))
            {
                throw new InvalidOperationException("The side of the node where the subtree had to be attached is not null");
            }
            size += Subtree.size;

            if (!Subtree.IsEmpty())
            {
                Subtree.root.parent = node;

                if (left)
                {
                    node.left = Subtree.root;
                }
                else
                {
                    node.right = Subtree.root;
                }

                Subtree.root = null;
                Subtree.size = 0;
            }
        }
예제 #2
0
        /// <summary>
        /// Attaches two LinkedBinaryTrees, Left and Right, to the left and the right
        /// respectively of a leaf position
        /// </summary>
        /// <param name="Node"></param>
        /// <param name="Left"></param>
        /// <param name="Right"></param>
        public void Attach(Position Node, LinkedBinaryTree <T> Left, LinkedBinaryTree <T> Right)
        {
            Node node = validate(Node);

            if (!IsLeaf(Node))
            {
                throw new InvalidOperationException("The position Node is not a leaf");
            }
            size += Left.size + Right.size;

            if (!Left.IsEmpty())
            {
                Left.root.parent = node;
                node.left        = Left.root;
                Left.root        = null;
                Left.size        = 0;
            }
            if (!Right.IsEmpty())
            {
                Right.root.parent = node;
                node.right        = Right.root;
                Right.root        = null;
                Right.size        = 0;
            }
        }
예제 #3
0
 public Position(LinkedBinaryTree <T> container, Node Node)
 {
     this.Node      = Node;
     this.container = container;
 }