(node)
| 152 | |
| 153 | // check if tree is balanced after deletion |
| 154 | const delBalance = function (node) { |
| 155 | const balanceFactor1 = getHeightDifference(node) |
| 156 | if (isValidBalanceFactor(balanceFactor1)) { |
| 157 | return node |
| 158 | } |
| 159 | if (balanceFactor1 > 1) { |
| 160 | if (getHeightDifference(node._left) >= 0) { |
| 161 | return rightRotate(node) // Left Left |
| 162 | } |
| 163 | node._left = leftRotate(node._left) |
| 164 | return rightRotate(node) // Left Right |
| 165 | } |
| 166 | if (getHeightDifference(node._right) > 0) { |
| 167 | node._right = rightRotate(node._right) |
| 168 | return leftRotate(node) // Right Left |
| 169 | } |
| 170 | return leftRotate(node) // Right Right |
| 171 | } |
| 172 | |
| 173 | // implement avl tree insertion |
| 174 | const insert = function (root, val, tree) { |
no test coverage detected