正确的代码:
Node successor = maximumNode(node.left);
successor.left = removeMax(node.left);//size ++;
successor.right = node.right;
node.left = node.right = null;//size --
return successor;
=====================
报错的代码:
Node successor = maximumNode(node.left);
successor.right = node.right;
successor.left = removeMax(node.left);//size ++;
node.left = node.right = null;//size --
return successor;
测试用例:
public static void main(String[] args) {
BST<Integer> bst = new BST<>();
int[] arr = {50, 28, 58, 22, 29, 54, 60, 52, 56};
for(int i = 0 ; i < 9 ; i ++){
bst.add(arr[i]);
}
System.out.println(bst);
bst.remove(50);
System.out.println(bst);
}
交换了两行代码的顺序,就会报错,求解,谢谢老师。