Posted by kalpol on July 30, 2001 at 14:40:07:
In Reply to: corrections posted by quyen on July 29, 2001 at 21:41:53:
: : void leftToRightRotate (treeNode * & root)
: : {
: : treeNode * psave = root->psave;
: : treeNode * save = root;
: : root = save->leftChild;
: : save->leftChild = root->rightChild;
: : root->rightChild = save;
: : root->parent = psave->parent;
: : save->parent = root;
: : save->leftChild->parent = save;
: : }
: : //3 parent pointers are updated
: corrections the first line should be:
: treeNode * psave = root->parent;
When you set the new root to save's child, the parent pointer points to itself - so when you set root's parent to the saved parent, if the parent is NULL, then root becomes NULL and everything goes to hell. i haven't figure out why. i don't know if it works otherwise.