예제 #1
0
    def insert(self, e: Any):
        """插入"""
        x = self.search(e)
        if x:
            return x

        x = BinNode(e, parent=self._hot, lc=None,
                    rc=None)  # 创立红节点x:以self._hot为父节点,黑高度为-1
        x.height = -1

        if not self._hot:
            self._root = x

        else:

            if e < self._hot.data:
                self._hot.lc = x
            else:
                self._hot.rc = x

        self._size += 1
        self._solveDoubleRed(x)

        if x:
            return x
        else:
            return self._hot.parent
예제 #2
0
 def _updateHeight(self, x: BinNode):
     """更新节点高度"""
     x.height = max(stature(x.lc), stature(x.rc))
     if RedBlack.IsBlack(x):
         x.height += 1
     return x.height