if (bf < -1 || bf > 1) {
const d1 = stack[i][0];
const d2 = stack[i + 1][0];
if (d1 === Dir.Right && d2 === Dir.Right) {
//right, right -> rotate left
stack[i][1] = node.rotateLeft();
// left, left -> rotate right
stack[i][1] = node.rotateRight();