class AVLNode(BiTreeNode):
def __init__(self,data):
BiTreeNode.__init__(self,data)
self.bf = 0 #balance factor 平衡因子,记录左右子树高度差
class AVLTree(BST):
def __init__(self,li = None):
BST.__init__(self,li)
def rotate_left(self,p,c):
s2 = c.lchild #c的左节点变成了p的右节点
p.rchild = s2
if s2:
s2.parent = p
c.lchild = p
p.parent = c
p.bf = 0
c.bf = 0
return c#返回根节点
def rotata_right(self,p,c):
s2 = c.rchild # c的右节点变成了p的左节点
p.lchild = s2
if s2:
s2.parent = p
c