Cân bằng AVL

void LL(AVLTree &T)

{

AVLNode *T1=T->pLeft;

T->pLeft = T1->pRight;

T1->pRight=T;

switch(T1-> balFactor)

{ case LH: T-> balFactor =EH;

T1->balFactor=EH; break;

case EH: T->balFactor=LH;

T1->balFactor =RH; break;

}

T=T1;

}

-------------------------------------------------------------------

void LR(AVLTree &T)

{ AVLNode *T1=T->pLeft;

AVLNode *T2=T1->pRight;

T->pLeft=T2->pRight;

T2->pRight=T;

T1->pRight= T2->pLeft;

T2->pLeft = T1;

switch(T2->balFactor)

{ case LH: T->balFactor=RH;

T1->balFactor=EH; break;

case EH: T->balFactor = EH;

T1->balFactor=EH; break;

case RH: T->balFactor =EH;

T1->balFactor= LH; break;

}

T2->balFactor =EH;

T=T2

}

------------------------------------------------------------------------------

void RR(AVLTree &T)

{ AVLNode *T1= T->pRight;

T->pRight=T1->pLeft;

T1->pLeft=T;

switch(T1-> balFactor)

{

case RH: T-> balFactor = EH;

T-> balFactor = EH; break;

case EH: T-> balFactor = RH;

T1-> balFactor = LH; break;

}

T=T1

}

--------------------------------------------------------------------------------

void RR(AVLTree &T)

{ AVLNode *T1= T->pRight;

AVLNode *T2=T1->pLeft;

T->pRight = T2->pLeft;

T2->pLeft = T;

T1->pLeft = T2->pRight;

T2->pRight = T1;

switch(T2-> balFactor)

{ case RH: T-> balFactor = LH;

T1-> balFactor = EH; break;

case EH: T-> balFactor = EH;

T1-> balFactor = EH; break;

case LH: T-> balFactor = EH;

T1-> balFactor = RH; break;

}

T2-> balFactor =EH; T=T2;}

------------------------------------------------------------------------------

Bạn đang đọc truyện trên: AzTruyen.Top

Tags: #code