Python 3.x RB树不适用于*某些*未排序的数组
这是导致错误的代码部分。比如说,插入的节点是5,12,10,那么它将导致运行时错误。但是,插入5,10,12将起作用。(尽管10,8,12起作用) 返回的错误为:Python 3.x RB树不适用于*某些*未排序的数组,python-3.x,red-black-tree,Python 3.x,Red Black Tree,这是导致错误的代码部分。比如说,插入的节点是5,12,10,那么它将导致运行时错误。但是,插入5,10,12将起作用。(尽管10,8,12起作用) 返回的错误为: if(node.parent.parent.parent.right == node.parent.parent): tnode = self.LR(node.parent.parent) node.parent.paren
if(node.parent.parent.parent.right == node.parent.parent):
tnode = self.LR(node.parent.parent)
node.parent.parent.parent.right = tnode
有人能帮我修一下吗?代码已经太大了,我感到困惑。首先,确保您实际上指的是“node.parent.parent.parent”,因为RB再平衡的常规规则只要求在任何给定阶段检查父母和祖父母
如果您实际上是指node.parent.parent.parent,请在选中“right”之前确保它不为null。如何处理这种情况?我不知道我到底应该做什么。是的,这正是我遇到问题的地方。事实上,我使用的是null.right节点,这毫无意义。
File "Solution.py", line 132, in Balance
if(node.parent.parent.parent.right == node.parent.parent):
AttributeError: 'NoneType' object has no attribute 'right'