代码如下:
public void test(BSTNode<T> z)
{
BSTNode<T> y;
if (z.left != null){
y = z.parent;
BSTNode<T> a;
a = y.left;
if (y != null){
System.out.println("before a "+a);
System.out.println("before y.left "+y.left);
System.out.println("befere z.parent.left "+z.parent.left);
y.left = null;
//a = null;
System.out.println("after a "+a);
System.out.println("after y.left "+y.left);
System.out.println("after z.parent.left "+z.parent.left);
}
}
}
打印结果如下:
before a threadSleep.BSTree$BSTNode@15db9742
before y.left threadSleep.BSTree$BSTNode@15db9742
befere z.parent.left threadSleep.BSTree$BSTNode@15db9742
after a threadSleep.BSTree$BSTNode@15db9742
after y.left null
after z.parent.left null
请问 “after a ”为什么不是null?
或者将代码:
y.left = null;
//a = null;
改为
//y.left = null;
a = null;
结果为:
before a threadSleep.BSTree$BSTNode@15db9742
before y.left threadSleep.BSTree$BSTNode@15db9742
befere z.parent.left threadSleep.BSTree$BSTNode@15db9742
after a threadSleep.BSTree$BSTNode@15db9742
after y.left null
after z.parent.left null
运行环境:
jdk1.8
缥缈止盈
交互式爱情
慕慕森
相关分类