trekhleb / javascript-algorithms

📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings
MIT License
187.68k stars 30.17k forks source link

should it be this right ? #460

Open cjgodfather opened 4 years ago

cjgodfather commented 4 years ago

https://github.com/trekhleb/javascript-algorithms/blob/ba2d8dc4a8e27659c1420fe52390cb7981df4a94/src/data-structures/tree/BinaryTreeNode.js#L133

victorjzsun commented 4 years ago

this should always exist. Since there is no restriction on parameters in JS, if node is undefined/null, setRight(node) is the same as removing the right child. If this line is omitted, this.right.parent = this; has a possibility of calling null.parent which would throw an error, since this.right = node from the previous line.