Я хочу поменять 2 узла в Java, вот мой класс узлов
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 любой намек ????