private BinNode <Q> LeftTurn <Q>(BinNode <Q> p) { var q = p.RightChild; p.RightChild = q.LeftChild; q.LeftChild = p; p.FixHeight(); q.FixHeight(); return(q); }
private BinNode <Q> Balance <Q>(BinNode <Q> p) { p.FixHeight(); if (p.BalanceFactor == 2) { if (p.RightChild.BalanceFactor < 0) { p.RightChild = RightTurn <Q>(p.RightChild); } p = LeftTurn <Q>(p); } if (p.BalanceFactor == -2) { if (p.LeftChild.BalanceFactor > 0) { p.LeftChild = LeftTurn <Q>(p.LeftChild); } p = RightTurn <Q>(p); } return(p); }