我想在Java中交换2个节点,这是我的节点类
public class Node {
int freq;
Node left,right,parent;
}
我想交换树中的2个节点
public void swap(Node a,Node b){
Node temp;
temp.freq=a.freq;
temp.parent=a.parent;
temp.left=a.left;
temp.right= a.right;
a.freq=b.freq;
a.left=b.left;
a.right=b.right;
a.parent=b.parent;
b.freq=temp.freq;
b.left=temp.left;
b.right=temp.right;
b.parent=temp.parent;
}
但是我发现两个节点的父节点都成为b.parent 有什么提示吗????