/** x y / \ / \ A y => x C / \ / \ B C A B */ private void leftRotate(Node<T> x) { Node<T> parent = x.parent; Node<T> y = x.right; Node<T> B = y.left; y.left = x; x.parent = y; x.right = B; if (B != null) B.parent = x; y.parent = parent; if (parent != null) { parent.replaceChild(x, y); } else { root = y; } updateHeight(x); }
private void addToRight(Node<T> parent, Node<T> newNode) { countNodes++; parent.right = newNode; newNode.parent = parent; }
private void addToLeft(Node<T> parent, Node<T> newNode) { countNodes++; parent.left = newNode; newNode.parent = parent; }