@@ -17,6 +17,7 @@ import sibling from '../family/sibling.js';
1717 * - if n is a right child, the left child of n's sibling is red
1818 *
1919 * @param {Node } n - The input node.
20+ * @return {Node } The root of the modified subtree.
2021 */
2122const delete_case5 = ( n ) => {
2223 assert ( n instanceof Node ) ;
@@ -28,8 +29,9 @@ const delete_case5 = (n) => {
2829
2930 /**
3031 * 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
3133 * 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.
3335 * We can repaint n's sibling's right child in black to fix this.
3436 * We are done.
3537 *
@@ -44,21 +46,23 @@ const delete_case5 = (n) => {
4446 * - -
4547 */
4648
49+ // Swap the color of the parent and the sibling.
4750 s . _color = n . parent . _color ;
4851 n . parent . _color = BLACK ;
4952
5053 if ( n === n . parent . left ) {
5154 assert ( s . right . _color === RED ) ;
5255 s . right . _color = BLACK ;
5356 rotate_left ( n . parent ) ;
57+ return s ;
5458 }
5559
5660 // 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 ;
6266} ;
6367
6468export default delete_case5 ;
0 commit comments