Update red_black_tree.py

This commit is contained in:
树哥 2018-11-25 16:18:57 +08:00 committed by GitHub
parent 3b2b98e483
commit 7935ed66ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -253,7 +253,7 @@ class RedBlackTree:
# 注意因为p可能是红或黑所以不能直接赋值颜色只能copy # 注意因为p可能是红或黑所以不能直接赋值颜色只能copy
b.color = p.color # case 4 b.color = p.color # case 4
p.set_black() # case 4 p.set_black() # case 4
b.left.set_black() # case 4 b.left.set_black() # case 4
self.rotate_r(p) # case 4 self.rotate_r(p) # case 4
# trick, 调整结束跳出while # trick, 调整结束跳出while
n = self.root # case 4 n = self.root # case 4
@ -329,7 +329,7 @@ class RedBlackTree:
if node.left is self.black_leaf: if node.left is self.black_leaf:
return return
# raise Exception('try rotate left , but the node "{}" has no left child'.format(node.val)) # raise Exception('try rotate right , but the node "{}" has no left child'.format(node.val))
p = self.parent(node) p = self.parent(node)
x = node x = node