(data, currentNode)
| 34 | } |
| 35 | |
| 36 | #insertNode(data, currentNode) { |
| 37 | if (!currentNode) { |
| 38 | return new AVLNode(data); |
| 39 | } |
| 40 | |
| 41 | if (this.#compareFn.lessThan(data, currentNode.data)) { |
| 42 | currentNode.left = this.#insertNode(data, currentNode.left); |
| 43 | } else { |
| 44 | currentNode.right = this.#insertNode(data, currentNode.right); |
| 45 | } |
| 46 | |
| 47 | currentNode.height = this.#updateNodeHeight(currentNode); |
| 48 | |
| 49 | return this.#balance(currentNode); |
| 50 | } |
| 51 | |
| 52 | #updateNodeHeight(node) { |
| 53 | return 1 + Math.max(this.#getHeight(node.left), this.#getHeight(node.right)); |
no test coverage detected