private RBNode successor(RBNode x) {
        if (x.hasRightChild()) {
            return x.getRightChild().minNode();
        } else {
            RBNode y = x.getParent();
            while (!y.isNil() && x == y.getRightChild()) {
                x = y;
                y = y.getParent();
            }
            return y;
        }
    }