左单旋转
void RotateLeft(AVLNode *&ptr)
{
AVLNode *newroot = ptr->rightchild;
newroot->parent = ptr->parent;
ptr->rightchild= newroot->leftchild;
if(newroot->leftchild != NULL)
{
newroot->->leftchild->parent = ptr;
}
newroot->leftchild = ptr;
ptr->parent = newroot;
ptr = newroot;
}
右单旋转
void RotateRight(AVLNode *&ptr)
{
AVLNode *newroot = ptr->leftchild;
newroot->parent = ptr->parent;
ptr->leftchild= newroot->rightchild;
if(newroot->rightchild != NULL)
{
newroot->->rightchild->parent = ptr;
}
newroot->rightchild = ptr;
ptr->parent = newroot;
ptr = newroot;
}