File tree 1 file changed +4
-2
lines changed
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';
5
5
import Leaf from '../types/Leaf.js' ;
6
6
7
7
import replace_node from './replace_node.js' ;
8
- import delete_case1 from './delete_case1 .js' ;
8
+ import delete_case2 from './delete_case2 .js' ;
9
9
10
10
/**
11
11
* Delete a node <code>n</code> that has at most a single non-leaf child.
12
12
*
13
13
* Precondition:
14
14
* - n has at most one non-leaf child.
15
+ * - n is not the root
15
16
* - if n has a non-leaf child, then it is its left child.
16
17
* - hence, n's right child is a leaf
17
18
*
18
19
* @param {Node } n - The node to delete.
19
20
*/
20
21
const delete_one_child = ( n ) => {
21
22
assert ( n instanceof Node ) ;
23
+ assert ( n . parent !== null ) ;
22
24
// Precondition: n's right child is a leaf.
23
25
// The right child of n is always a LEAF because either n is a subtree
24
26
// predecessor or it is the only child of its parent by the red-black tree
@@ -39,7 +41,7 @@ const delete_one_child = (n) => {
39
41
if ( child . _color === RED ) child . _color = BLACK ;
40
42
// Otherwise, there are more things to fix.
41
43
else {
42
- delete_case1 ( child ) ;
44
+ delete_case2 ( child ) ;
43
45
}
44
46
} else {
45
47
// 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