Pointer mysteriously moves
Posted
by
Armen Ablak
on Stack Overflow
See other posts from Stack Overflow
or by Armen Ablak
Published on 2011-01-09T00:50:45Z
Indexed on
2011/01/09
0:53 UTC
Read the original article
Hit count: 161
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.
© Stack Overflow or respective owner