예제 #1
0
 private static AvlNode <T> Balance(AvlNode <T> node)
 {
     FixHeight(node);
     if (GetBalanceFactor(node) == 2)
     {
         if (GetBalanceFactor(node.Right) < 0)
         {
             RotateRight(node.Right);
         }
         RotateLeft(node);
     }
     else if (GetBalanceFactor(node) == -2)
     {
         if (GetBalanceFactor(node.Left) < 0)
         {
             RotateLeft(node.Left);
         }
         RotateRight(node);
     }
     return(node);
 }
예제 #2
0
 public override void Insert(T item)
 {
     Root = Insert(Root, item);
     Count++;
 }
예제 #3
0
 private static int GetHeight(AvlNode <T> node) => node?.Height ?? 0;
예제 #4
0
 private static int GetBalanceFactor(AvlNode <T> node) => GetHeight(node?.Right) - GetHeight((node?.Left));