def turnLeft(self, rotateRoot: TreeNode): newRoot = rotateRoot.rightChild rotateRoot.rightChild = newRoot.leftChild if newRoot.leftChild is not None: newRoot.leftChild.parent = rotateRoot newRoot.parent = rotateRoot.parent if rotateRoot.isRoot(): self.root = newRoot else: if rotateRoot.isLeftChild(): rotateRoot.parent.leftChild = newRoot else: rotateRoot.parent.rightChild = newRoot newRoot.leftChild = rotateRoot rotateRoot.parent = newRoot
def __checkAfterInsert__(self, node: TreeNode): if node.isRoot(): node.setBlackColor() else: self.__checkNodeIsRed__(node)