Exemple #1
0
 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
Exemple #2
0
 def __checkAfterInsert__(self, node: TreeNode):
     if node.isRoot():
         node.setBlackColor()
     else:
         self.__checkNodeIsRed__(node)