(root, val, tree)
| 172 | |
| 173 | // implement avl tree insertion |
| 174 | const insert = function (root, val, tree) { |
| 175 | if (root == null) { |
| 176 | tree.size++ |
| 177 | return new Node(val) |
| 178 | } |
| 179 | if (tree._comp(root._val, val) < 0) { |
| 180 | root._right = insert(root._right, val, tree) |
| 181 | } else if (tree._comp(root._val, val) > 0) { |
| 182 | root._left = insert(root._left, val, tree) |
| 183 | } else { |
| 184 | return root |
| 185 | } |
| 186 | updateHeight(root) |
| 187 | const balanceFactor = getHeightDifference(root) |
| 188 | return isValidBalanceFactor(balanceFactor) |
| 189 | ? root |
| 190 | : insertBalance(root, val, balanceFactor, tree) |
| 191 | } |
| 192 | |
| 193 | // delete am element |
| 194 | const deleteElement = function (root, _val, tree) { |
no test coverage detected