public void balance() {
        int r = 0, l = 0, d;
        if (right != null) r = right.height();
        if (left != null) l = left.height();
        d = r - l;
        if (Math.abs(d) <= 1) return;
        if (d > 0) rotateLeft();
        if (d < 0) rotateRight();

        for (Node<T> child : children()) {
            if (child != null) child.balance();
        }
    }