Exemplo n.º 1
0
        private void Insert_4b_Outside(RedBlackTreeNode node)
        {
            RedBlackTreeNode nodeParent      = (RedBlackTreeNode)node.Parent;
            RedBlackTreeNode nodeGrandParent = (RedBlackTreeNode)node.GrandParent();

            if (node == nodeParent.Left)
            {
                Rotate_Right(nodeGrandParent);
            }
            else
            {
                Rotate_Left(nodeGrandParent);
            }
            nodeParent.Color      = BLACK;
            nodeGrandParent.Color = RED;
        }
Exemplo n.º 2
0
        private void Insert_4a_RedParent_BlackUncle(RedBlackTreeNode node)
        {
            RedBlackTreeNode nodeParent      = (RedBlackTreeNode)node.Parent;
            RedBlackTreeNode nodeGrandParent = (RedBlackTreeNode)node.GrandParent();

            if (node == nodeParent.Right && nodeParent == nodeGrandParent.Left)
            {
                Rotate_Left(nodeParent);
                node = (RedBlackTreeNode)node.Left;
            }
            else if (node == nodeParent.Left && nodeParent == nodeGrandParent.Right)
            {
                Rotate_Right(nodeParent);
                node = (RedBlackTreeNode)node.Right;
            }

            Insert_4b_Outside(node);
        }
Exemplo n.º 3
0
        private void Insert_3_ParentUncleRed(RedBlackTreeNode node)
        {
            RedBlackTreeNode nodeParent = (RedBlackTreeNode)node.Parent;

            if (nodeParent != null)
            {
                nodeParent.Color = BLACK;
            }

            RedBlackTreeNode nodeUncle = (RedBlackTreeNode)node.Uncle();

            if (nodeUncle != null)
            {
                nodeUncle.Color = BLACK;
            }

            RedBlackTreeNode grandParent = (RedBlackTreeNode)node.GrandParent();

            if (grandParent != null)
            {
                grandParent.Color = RED;
                Insert_Repair_Tree(grandParent);
            }
        }