(Code)
cout<<"D)x is "<<x->key<<endl;
y->parent=x->parent;
cout<<"E)x is "<<x->key<<endl;
(Output)
D)x is 11
E)x is 0
I have been very unspecific about the rest of the code, but I really expected not to see any change between the two output lines, since I dont (excuse me ) bloody change either x or x->key.
It is pare of the rotate right routinein red-black trees. It seemed to work fine until ot got called by the red black insert fixup routine.
Program: Dev-C++ v 4.9.9.2
OS: Windows 7 Professional 64-bit
I can supply any further info required, but I really hope its something simple I've missed.
Part of my code:
typedef struct node * p;
struct node
{
int key;
p left,right,parent;
};
y->parent is indeed x at the time of the cout<<"D)...".
I understand this because cout<<y->parent->key yields output 11.
Is there something wrong with this?
the only way that would make any sense would be if 'x' somehow pointed to y->parent or one of it's members. Of course that wouldn't be intentional on your part, so I suspect you're assigning a pointer incorrectly somewhere.