File tree 5 files changed +16
-0
lines changed 5 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -7,12 +7,15 @@ import insert_case2 from './insert_case2.js';
7
7
/**
8
8
* Preconditions:
9
9
* - n is red.
10
+ * - n's children are BLACK
10
11
*
11
12
* @param {Node } n - The input node.
12
13
*/
13
14
const insert_case1 = ( n ) => {
14
15
assert ( n instanceof Node ) ;
15
16
assert ( n . _color === RED ) ;
17
+ assert ( n . left . _color === BLACK ) ;
18
+ assert ( n . right . _color === BLACK ) ;
16
19
/**
17
20
* If n is the root of the tree, paint it black and we are done.
18
21
*
Original file line number Diff line number Diff line change @@ -7,13 +7,16 @@ import insert_case3 from './insert_case3.js';
7
7
/**
8
8
* Preconditions:
9
9
* - n is red.
10
+ * - n's children are BLACK
10
11
* - n is not the root of the tree.
11
12
*
12
13
* @param {Node } n - The input node.
13
14
*/
14
15
const insert_case2 = ( n ) => {
15
16
assert ( n instanceof Node ) ;
16
17
assert ( n . _color === RED ) ;
18
+ assert ( n . left . _color === BLACK ) ;
19
+ assert ( n . right . _color === BLACK ) ;
17
20
assert ( n . parent !== null ) ;
18
21
19
22
/**
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import insert_case4 from './insert_case4.js';
10
10
/**
11
11
* Preconditions:
12
12
* - n is red.
13
+ * - n's children are BLACK
13
14
* - n is not the root of the tree.
14
15
* - n's parent is red.
15
16
*
@@ -18,6 +19,8 @@ import insert_case4 from './insert_case4.js';
18
19
const insert_case3 = ( n ) => {
19
20
assert ( n instanceof Node ) ;
20
21
assert ( n . _color === RED ) ;
22
+ assert ( n . left . _color === BLACK ) ;
23
+ assert ( n . right . _color === BLACK ) ;
21
24
assert ( n . parent !== null ) ;
22
25
assert ( n . parent . _color === RED ) ;
23
26
const u = uncle ( n ) ;
Original file line number Diff line number Diff line change 1
1
import assert from 'assert' ;
2
2
import Node from '../adt/Node.js' ;
3
+ import BLACK from '../color/BLACK.js' ;
3
4
import RED from '../color/RED.js' ;
4
5
import rotate_left from '../rotate/rotate_left.js' ;
5
6
import rotate_right from '../rotate/rotate_right.js' ;
@@ -9,6 +10,7 @@ import insert_case5 from './insert_case5.js';
9
10
/**
10
11
* Preconditions:
11
12
* - n is red.
13
+ * - n's children are BLACK
12
14
* - n is not the root of the tree.
13
15
* - n's parent is red.
14
16
* - n's uncle is black.
@@ -20,6 +22,8 @@ import insert_case5 from './insert_case5.js';
20
22
const insert_case4 = ( n ) => {
21
23
assert ( n instanceof Node ) ;
22
24
assert ( n . _color === RED ) ;
25
+ assert ( n . left . _color === BLACK ) ;
26
+ assert ( n . right . _color === BLACK ) ;
23
27
assert ( n . parent !== null ) ;
24
28
assert ( n . parent . _color === RED ) ;
25
29
const g = grandparent ( n ) ;
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import grandparent from '../family/grandparent.js';
9
9
/**
10
10
* Preconditions:
11
11
* - n is red.
12
+ * - n's children are BLACK
12
13
* - n is not the root of the tree.
13
14
* - n's parent is red.
14
15
* - n's uncle is black.
@@ -19,6 +20,8 @@ import grandparent from '../family/grandparent.js';
19
20
const insert_case5 = ( n ) => {
20
21
assert ( n instanceof Node ) ;
21
22
assert ( n . _color === RED ) ;
23
+ assert ( n . left . _color === BLACK ) ;
24
+ assert ( n . right . _color === BLACK ) ;
22
25
assert ( n . parent !== null ) ;
23
26
assert ( n . parent . _color === RED ) ;
24
27
const g = grandparent ( n ) ;
You can’t perform that action at this time.
0 commit comments