我正在尝试将AVL(左)轮换实施为: Example of left rotation
对于该节点,我使用一个结构:
struct Node {
int value;
int balance;
int height;
Node* right;
Node* left;
Node* parent;
};
这是我的轮换代码:
void AVL::left_rotation(Node* &y) {
Node* T2 = y->right->left;
Node* x = y->right;
x->left = y;
y->right = T2;
if (y->parent != NULL) {
x->parent = y->parent;
if (x->parent->left == y) {
x->parent->left = x;
}
else {
x->parent->right = x;
}
}
else {
m_root = x;
}
y->parent = x;
if (T2 != NULL) {
T2->parent = y;
}
}
执行行x->parent = y->parent;
时,节点*y
被*(y->parent)
替换。我该如何解决?为什么会发生?我是C ++的新手,我想了解指针。