Пример #1
0
 private void Case1(RBNode node)
 {
     node.Parent.Color = Color.Black;
     node.Uncle().Color       = Color.Black;
     node.Grandparent().Color = Color.Red;
     RepairTree(node.Grandparent());
 }
Пример #2
0
        private void Case2(RBNode node)
        {
            if (node == node.Grandparent().RBNodeLeft.RBNodeRight)
            {
                RotateLeft(node.Parent);
                if (node.RBNodeLeft.leaf != Leaf.LEAF)
                {
                    node = node.RBNodeLeft;
                }
            }
            else if (node == node.Grandparent().RBNodeRight.RBNodeLeft)
            {
                RotateRight(node.Parent);
                if (node.RBNodeRight.leaf != Leaf.LEAF)
                {
                    node = node.RBNodeRight;
                }
            }



            if (node == node.Parent.RBNodeLeft)
            {
                RotateRight(node.Parent);
            }
            else
            {
                RotateLeft(node.Parent);
            }
            node.Parent.Color = Color.Black;

            if (node.Grandparent() != null)
            {
                node.Grandparent().Color = Color.Red;
            }
        }