@@ -51,18 +51,13 @@ def rotate_left(self) -> RedBlackTree:
51
51
"""
52
52
parent = self .parent
53
53
right = self .right
54
-
55
54
if right is None :
56
55
return self
57
-
58
56
self .right = right .left
59
-
60
57
if self .right :
61
58
self .right .parent = self
62
59
self .parent = right
63
-
64
60
right .left = self
65
-
66
61
if parent is not None :
67
62
if parent .left == self :
68
63
parent .left = right
@@ -80,14 +75,10 @@ def rotate_right(self) -> RedBlackTree:
80
75
return self
81
76
parent = self .parent
82
77
left = self .left
83
-
84
78
self .left = left .right
85
-
86
79
if self .left :
87
80
self .left .parent = self
88
-
89
81
self .parent = left
90
-
91
82
left .right = self
92
83
93
84
if parent is not None :
@@ -186,7 +177,6 @@ def remove(self, label: int) -> RedBlackTree:
186
177
# is if both children are None leaves.
187
178
# We can just remove this node and call it a day.
188
179
if self .parent :
189
-
190
180
if self .is_left ():
191
181
self .parent .left = None
192
182
else :
@@ -314,21 +304,17 @@ def check_color_properties(self) -> bool:
314
304
"""
315
305
# I assume property 1 to hold because there is nothing that can
316
306
# make the color be anything other than 0 or 1.
317
-
318
307
# Property 2
319
308
if self .color :
320
309
# The root was red
321
310
print ("Property 2" )
322
311
return False
323
-
324
312
# Property 3 does not need to be checked, because None is assumed
325
313
# to be black and is all the leaves.
326
-
327
314
# Property 4
328
315
if not self .check_coloring ():
329
316
print ("Property 4" )
330
317
return False
331
-
332
318
# Property 5
333
319
if self .black_height () is None :
334
320
print ("Property 5" )
@@ -385,7 +371,6 @@ def search(self, label: int) -> RedBlackTree | None:
385
371
"""
386
372
if self .label == label :
387
373
return self
388
-
389
374
elif self .label is not None and label > self .label :
390
375
if self .right is None :
391
376
return None
@@ -474,7 +459,6 @@ def is_left(self) -> bool:
474
459
"""Returns true iff this node is the left child of its parent."""
475
460
if self .parent is None :
476
461
return False
477
-
478
462
return self .parent .left is self .parent .left is self
479
463
480
464
def is_right (self ) -> bool :
@@ -491,7 +475,6 @@ def __len__(self) -> int:
491
475
Return the number of nodes in this tree.
492
476
"""
493
477
ln = 1
494
-
495
478
if self .left :
496
479
ln += len (self .left )
497
480
if self .right :
0 commit comments