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