예제 #1
0
 public void ReverseNodes(RedBlackTree <T> .Node first, RedBlackTree <T> .Node last)
 {
     if (first == last)
     {
         return;
     }
     RedBlackTree <T> .Node child1 = first;
     RedBlackTree <T> .Node child2 = last;
     while (true)
     {
         RedBlackTree <T> .Node next     = child1.GetNext();
         RedBlackTree <T> .Node previous = child2.GetPrevious();
         bool flag = next == previous || next == child2;
         if (child1.Parent == child2)
         {
             RedBlackTree <T> .Node node = child1;
             child1 = child2;
             child2 = node;
         }
         RedBlackTree <T> .Node left1   = child1.Left;
         RedBlackTree <T> .Node right1  = child1.Right;
         RedBlackTree <T> .Node parent1 = child1.Parent;
         bool isRed1 = child1.IsRed;
         RedBlackTree <T> .Node left2   = child2.Left;
         RedBlackTree <T> .Node right2  = child2.Right;
         RedBlackTree <T> .Node parent2 = child2.Parent;
         bool isRed2 = child2.IsRed;
         if (child1.Right == child2)
         {
             child1.Left  = left2;
             child1.Right = right2;
             child2.Left  = left1;
             child2.Right = child1;
             if (parent1 == null)
             {
                 this.node_0   = child2;
                 child2.Parent = (RedBlackTree <T> .Node)null;
             }
             else
             {
                 parent1.method_1(parent1.Left == child1, child2);
             }
         }
         else if (child1.Left == child2)
         {
             child1.Left  = left2;
             child1.Right = right2;
             child2.Left  = child1;
             child2.Right = right1;
             if (parent1 == null)
             {
                 this.node_0   = child2;
                 child2.Parent = (RedBlackTree <T> .Node)null;
             }
             else
             {
                 parent1.method_1(parent1.Left == child1, child2);
             }
         }
         else
         {
             child1.Left  = left2;
             child1.Right = right2;
             if (parent2 == null)
             {
                 this.node_0   = child1;
                 child1.Parent = (RedBlackTree <T> .Node)null;
             }
             else
             {
                 parent2.method_1(parent2.Left == child2, child1);
             }
             child2.Left  = left1;
             child2.Right = right1;
             if (parent1 == null)
             {
                 this.node_0   = child2;
                 child2.Parent = (RedBlackTree <T> .Node)null;
             }
             else
             {
                 parent1.method_1(parent1.Left == child1, child2);
             }
         }
         child1.IsRed = isRed2;
         child2.IsRed = isRed1;
         if (!flag)
         {
             child1 = next;
             child2 = previous;
         }
         else
         {
             break;
         }
     }
 }