File tree Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change @@ -5,20 +5,22 @@ import Node from '../types/Node.js';
55import Leaf from '../types/Leaf.js' ;
66
77import replace_node from './replace_node.js' ;
8- import delete_case1 from './delete_case1 .js' ;
8+ import delete_case2 from './delete_case2 .js' ;
99
1010/**
1111 * Delete a node <code>n</code> that has at most a single non-leaf child.
1212 *
1313 * Precondition:
1414 * - n has at most one non-leaf child.
15+ * - n is not the root
1516 * - if n has a non-leaf child, then it is its left child.
1617 * - hence, n's right child is a leaf
1718 *
1819 * @param {Node } n - The node to delete.
1920 */
2021const delete_one_child = ( n ) => {
2122 assert ( n instanceof Node ) ;
23+ assert ( n . parent !== null ) ;
2224 // Precondition: n's right child is a leaf.
2325 // The right child of n is always a LEAF because either n is a subtree
2426 // predecessor or it is the only child of its parent by the red-black tree
@@ -39,7 +41,7 @@ const delete_one_child = (n) => {
3941 if ( child . _color === RED ) child . _color = BLACK ;
4042 // Otherwise, there are more things to fix.
4143 else {
42- delete_case1 ( child ) ;
44+ delete_case2 ( child ) ;
4345 }
4446 } else {
4547 // If n is red then its child can only be black. Replacing n with its
You can’t perform that action at this time.
0 commit comments