(node, _val, balanceFactor, tree)
| 136 | |
| 137 | // check if tree is balanced else balance it for insertion |
| 138 | const insertBalance = function (node, _val, balanceFactor, tree) { |
| 139 | if (balanceFactor > 1 && tree._comp(_val, node._left._val) < 0) { |
| 140 | return rightRotate(node) // Left Left Case |
| 141 | } |
| 142 | if (balanceFactor < 1 && tree._comp(_val, node._right._val) > 0) { |
| 143 | return leftRotate(node) // Right Right Case |
| 144 | } |
| 145 | if (balanceFactor > 1 && tree._comp(_val, node._left._val) > 0) { |
| 146 | node._left = leftRotate(node._left) // Left Right Case |
| 147 | return rightRotate(node) |
| 148 | } |
| 149 | node._right = rightRotate(node._right) |
| 150 | return leftRotate(node) |
| 151 | } |
| 152 | |
| 153 | // check if tree is balanced after deletion |
| 154 | const delBalance = function (node) { |
no test coverage detected