예제 #1
0
            private static Node <T> RotateLeft(Node <T> n)
            {
                Node <T> result = n.Right;

                n.Right     = result.Left;
                result.Left = n;
                n.FixHeight();
                result.FixHeight();
                return(result);
            }
예제 #2
0
파일: AVLTree.cs 프로젝트: Crozby/AVLTree
            public Node RightRotate()
            {
                Node q = Left;

                Left    = q.Right;
                q.Right = this;
                this.FixHeight();
                q.FixHeight();
                return(q);
            }
예제 #3
0
파일: AVLTree.cs 프로젝트: Crozby/AVLTree
            public Node LeftRotate()
            {
                Node p = Right;

                Right  = p.Left;
                p.Left = this;
                this.FixHeight();
                p.FixHeight();
                return(p);
            }
예제 #4
0
 public static Node <T> Balance(Node <T> n)
 {
     n.FixHeight();
     if (n.BalanceFactor() == -2)
     {
         if (n.Right.BalanceFactor() > 0)
         {
             n.Right = RotateRight(n.Right);
         }
         return(RotateLeft(n));
     }
     if (n.BalanceFactor() == 2)
     {
         if (n.Left.BalanceFactor() < 0)
         {
             n.Left = RotateLeft(n.Left);
         }
         return(RotateRight(n));
     }
     return(n);
 }
예제 #5
0
파일: AVLTree.cs 프로젝트: Crozby/AVLTree
 private static Node DoBalance(Node node)
 {
     node.FixHeight();
     if (node.BalanceFactor() == 2)
     {
         if (node.Right.BalanceFactor() < 0)
         {
             node.Right = node.Right.RightRotate();
         }
         return(node.LeftRotate());
     }
     if (node.BalanceFactor() == -2)
     {
         if (node.Left.BalanceFactor() > 0)
         {
             node.Left = node.Left.LeftRotate();
         }
         return(node.RightRotate());
     }
     return(node);
 }