Exemplo n.º 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);
 }
Exemplo n.º 2
0
 public override void Insert(T item)
 {
     Root = Insert(Root, item);
     Count++;
 }
Exemplo n.º 3
0
 private static int GetHeight(AvlNode <T> node) => node?.Height ?? 0;
Exemplo n.º 4
0
 private static int GetBalanceFactor(AvlNode <T> node) => GetHeight(node?.Right) - GetHeight((node?.Left));