Posted by kalpol on July 28, 2001 at 14:34:00:
ok
I'm writing a splay tree for my map.
I have a rotate function that worked for the AVL tree but since I added parent pointers it went all to hell.
treenode*& rotateL (treenode*& root)
{
//cout << "Left Rotate " << endl;
treenode* save = root->parent;
treenode* saveparent = save->parent;
//root->parent = save->rc;
root->parent->rc = root->lc;
on the second insert, it tries to rotate, given the new node (ie, a root node and a right child make the tree, so a left rotate is needed)
but when it gets to the last line, it sets root (the new node, not the root of the tree which is save) to NULL instead of setting its parent's right-child to POINT to NULL (even if that happens to be the root, i just want the rightchild pointer reset, not the node it's pointing to). what the hell am i doing wrong???? this is all that's holding me up....and it's been like, a day. i've tried everything. No help from Peiyu or Van Weiren, either. this class sucks!