@@ -17,6 +17,7 @@ import sibling from '../family/sibling.js';
17
17
* - if n is a right child, the left child of n's sibling is red
18
18
*
19
19
* @param {Node } n - The input node.
20
+ * @return {Node } The root of the modified subtree.
20
21
*/
21
22
const delete_case5 = ( n ) => {
22
23
assert ( n instanceof Node ) ;
@@ -28,8 +29,9 @@ const delete_case5 = (n) => {
28
29
29
30
/**
30
31
* Increment the black height of all root-leaf paths going through n by
32
+ * swapping the colors of n's parent and n's sibling and
31
33
* rotating at n's parent. This decrements the black height of all
32
- * root-leaft paths going through n's sibling's right child.
34
+ * root-leaf paths going through n's sibling's right child.
33
35
* We can repaint n's sibling's right child in black to fix this.
34
36
* We are done.
35
37
*
@@ -44,21 +46,23 @@ const delete_case5 = (n) => {
44
46
* - -
45
47
*/
46
48
49
+ // Swap the color of the parent and the sibling.
47
50
s . _color = n . parent . _color ;
48
51
n . parent . _color = BLACK ;
49
52
50
53
if ( n === n . parent . left ) {
51
54
assert ( s . right . _color === RED ) ;
52
55
s . right . _color = BLACK ;
53
56
rotate_left ( n . parent ) ;
57
+ return s ;
54
58
}
55
59
56
60
// Symmetric case
57
- else {
58
- assert ( s . left . _color === RED ) ;
59
- s . left . _color = BLACK ;
60
- rotate_right ( n . parent ) ;
61
- }
61
+
62
+ assert ( s . left . _color === RED ) ;
63
+ s . left . _color = BLACK ;
64
+ rotate_right ( n . parent ) ;
65
+ return s ;
62
66
} ;
63
67
64
68
export default delete_case5 ;
0 commit comments