コード例 #1
0
ファイル: RedBlackTree.cs プロジェクト: bfdes/Collections
 public Node MoveLeft()
 {
     FlipColors();
     if (IsRed(right.left))
     {
         right = right.RotateRight();
         var n = RotateLeft();
         return(n.FlipColors());
     }
     return(this);
 }
コード例 #2
0
ファイル: RedBlackTree.cs プロジェクト: bfdes/Collections
 private Node Balance(Node n)
 {
     if (IsRed(n.right))
     {
         n = n.RotateLeft();
     }
     if (IsRed(n.left) && IsRed(n.left.left))
     {
         n = n.RotateRight();
     }
     if (IsRed(n.left) && IsRed(n.right))
     {
         n.FlipColors();
     }
     n.size = Size(n.left) + Size(n.right) + 1;
     return(n);
 }