|
67 | 67 | return new Node(key, value, null, null, Colors.RED); |
68 | 68 | } |
69 | 69 | if (node.getKey() > key) { |
70 | | - node._left = this._put(key, value, node._left); |
| 70 | + node.setLeft(this._put(key, value, node.getLeft())); |
71 | 71 | } else if (node.getKey() < key) { |
72 | | - node._right = this._put(key, value, node._right); |
| 72 | + node.setRight(this._put(key, value, node.getRight())); |
73 | 73 | } else { |
74 | 74 | node.setValue(value); |
75 | 75 | } |
76 | | - if (this.isRed(node._right) && !this.isRed(node._left)) { |
| 76 | + if (this.isRed(node.getRight()) && !this.isRed(node.getLeft())) { |
77 | 77 | newRoot = this._rotateLeft(node); |
78 | 78 | } |
79 | | - if (this.isRed(node._left) && this.isRed(node._left._left)) { |
| 79 | + if (this.isRed(node.getLeft()) && this.isRed(node.getLeft().getLeft())) { |
80 | 80 | newRoot = this._rotateRight(node); |
81 | 81 | } |
82 | | - if (this.isRed(node._left) && this.isRed(node._right)) { |
| 82 | + if (this.isRed(node.getLeft()) && this.isRed(node.getRight())) { |
83 | 83 | this._flipColors(node); |
84 | 84 | } |
85 | 85 | return newRoot; |
86 | 86 | }; |
87 | 87 |
|
88 | 88 | RBTree.prototype._flipColors = function (node) { |
89 | | - node._left.flipColor(); |
90 | | - node._right.flipColor(); |
| 89 | + node.getLeft().flipColor(); |
| 90 | + node.getRight().flipColor(); |
91 | 91 | }; |
92 | 92 |
|
93 | 93 | RBTree.prototype._rotateLeft = function (node) { |
94 | | - var x = node._right; |
| 94 | + var x = node.getRight(); |
95 | 95 | if (x !== null) { |
96 | | - var temp = x._left; |
| 96 | + var temp = x.getLeft(); |
97 | 97 | node.setRight(temp); |
98 | | - x._left = node; |
| 98 | + x.setLeft(node); |
99 | 99 | x.setColor(node.getColor()); |
100 | 100 | node.setColor(Colors.RED); |
101 | 101 | } |
102 | 102 | return x; |
103 | 103 | }; |
104 | 104 |
|
105 | 105 | RBTree.prototype._rotateRight = function (node) { |
106 | | - var x = node._left; |
| 106 | + var x = node.getLeft(); |
107 | 107 | if (x !== null) { |
108 | | - var temp = x._right; |
109 | | - node._left = temp; |
110 | | - x._right = node; |
| 108 | + var temp = x.getRight(); |
| 109 | + node.setLeft(temp); |
| 110 | + x.setRight(node); |
111 | 111 | x.setColor(node.getColor()); |
112 | 112 | node.setColor(Colors.RED); |
113 | 113 | } |
|
0 commit comments