在删除红黑树的最小节点时,为什么很多的代码都不需要处理最小节点(待删除)的右子节点,而是直接返回null,那其右子节点不就消失了吗?
private Node deleteMin(Node x) {
if (x.left == null) {
return null;
}
if (!isRed(x.left) && !isRed(x.left.left)) {
x = moveRedLeft(x);
}
x.left = deleteMin(x.left);
return balance(x);
}
private Node moveRedLeft(Node x) {
flipColors(x);
if (isRed(x.right.left)) {
x.right = rotateRight(x.right);
x = rotateLeft(x);
flipColors(x);
}
return x;
}