File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -100,6 +100,12 @@ export default class BinaryTreeNode {
100
100
* @return {BinaryTreeNode }
101
101
*/
102
102
setLeft ( node ) {
103
+
104
+ // Check if it is a proper node.
105
+ if ( node && ! ( node instanceof BinaryTreeNode ) ) {
106
+ throw new Error ( 'The left node must be an instance of BinaryTreeNode' ) ;
107
+ }
108
+
103
109
// Reset parent for left node since it is going to be detached.
104
110
if ( this . left ) {
105
111
this . left . parent = null ;
@@ -121,6 +127,12 @@ export default class BinaryTreeNode {
121
127
* @return {BinaryTreeNode }
122
128
*/
123
129
setRight ( node ) {
130
+
131
+ // Check if it is a proper node.
132
+ if ( node && ! ( node instanceof BinaryTreeNode ) ) {
133
+ throw new Error ( 'The right node must be an instance of BinaryTreeNode' ) ;
134
+ }
135
+
124
136
// Reset parent for right node since it is going to be detached.
125
137
if ( this . right ) {
126
138
this . right . parent = null ;
You can’t perform that action at this time.
0 commit comments