Pointer mysteriously moves
- by Armen Ablak
Hi,
I have this code for Node rotation and in a line which is marked something happens and I don't really know what and why :).
//Test case
30
\
16
/
29
RotationRight(node->mParent); //call
template<class T>
void SplayTree<T>::RotationRight(SplayNode<T> *&node) const
{
SplayNode<T> *left = node->mLeft;
SplayNode<T> *parent = node->mParent;
node->mLeft = left->mRight;
if(left->HasRight())
left->mRight->mParent = node;
left->mRight = node; //node in this line points to 0x00445198 {30}
left->mParent = node->mParent; //and in this line it points to 0x00444fb8 {16} (node, not node->mParent)
node->mParent = left;
node = left;
}
Well, left-mParent points to node also, so I basically do node = node-mParent. The problem is I can't find a work around - how to unpin in from node and change it's pointing address without changing it's.