<强> bf 强>
<强> 强>
<强> 强>
, 。
,高度降低之后,就大大。
<强> 强>
//左旋转代码实现: void RotateL(节点*,父节点) { 节点*,subR =,父→_right; 节点*,subRL =, subR→_left; 时间=父→_right subRL; if (subRL !=, NULL) 时间=subRL→_parent 家长; ,,,,,,,节点*,ppNode =,父→_parent; 时间=subR→_left 家长; 时间=父→_parent subR; if (ppNode ==, NULL) { 时间=_root subR; 时间=subR→_parent 零; } 其他的 { if (parent ==, ppNode→_left) 时间=ppNode→_left subR; if (parent ==, ppNode→_right) 时间=ppNode→_right subR; 时间=subR→_parent ppNode; } 时间=父→_bf 0; 时间=subR→_bf 0; }
强>
//右旋转代码实现 void 旋转(节点*,父节点) { 节点*,subL =,父→_left; 节点*,subLR =, subL→_right; 时间=父→_left subLR; if (subLR !=, NULL) { 时间=subLR→_parent 家长; } 节点*,ppNode =,父→_parent; 时间=subL→_right 家长; ,,,父母→_parent =, subL; if (ppNode ==, NULL) { 时间=_root subL; 时间=subL→_parent 零; } 其他的 { if (parent ==, ppNode→_left) 时间=ppNode→_left subL; 其他的 时间=ppNode→_right subL; ,,,,,,,,,,subL→_parent =, ppNode; } 时间=父→_bf 0; 时间=subL→_bf 0; }
<强> 强>
//右左旋转 void RotateRL(节点*,父节点) { 节点*,subR =,父→_right; 节点*,subRL =, subR→_left; size_t bf =, subRL→_bf; 旋转(父→_right); RotateL(父); if (bf ==, 0) { 时间=父→_bf 0; 时间=subR→_bf 0; 时间=subRL→_bf 0; } else if (bf ==, 1) { 时间=subR→_bf 0; 父母→_bf =, 1; 时间=subRL→_bf 0; } 其他的 { 时间=父→_bf 0; 时间=subR→_bf 1; 时间=subRL→_bf 0; } }
<强> 强>
//左右双旋 void RotateLR(节点*,父节点) { 节点*,subL =,父→_left; 节点*,subLR =, subL→_right; size_t bf =, subLR→_bf; RotateL(父→_left); 旋转(父); if (bf ==, 0) { 时间=父→_bf 0; 时间=subL→_bf 0; 时间=subLR→_bf 0; } else if (bf ==, 1) { 时间=父→_bf 0; 时间=subL→_bf 1; 时间=subLR→_bf 0; } 其他的 { 父母→_bf =, 1; 时间=subL→_bf 0; 时间=subLR→_bf 0; } }
强>
template & lt; typename K, typename V> struct AVLTreeNode { int _bf; K _key; V _value; AVLTreeNode*, _left; AVLTreeNode *, _right; AVLTreeNode *, _parent; AVLTreeNode (const K&,钥匙,,const V&,值) :_bf (0) ,_key(关键) ,_value(值) ,_left(空) ,_right(空) ,_parent(空) {} }; 浅析AVL树算法