/** * This call balances the AVL node 'a' and returns the balanced node. * * @private * @param a the node to balance * @return the balanced node */ static PropPtr balance_node(PropPtr a) { int dh = height_diff(a); if (abs(dh) < 2) { fixup_height(a); } else { /* One might argue the brackets are not necessary here, but * this looked like a train wreck without them :) */ if (dh == 2) { if (height_diff(a->right) >= 0) { a = rotate_left_single(a); } else { a = rotate_left_double(a); } } else if (height_diff(a->left) <= 0) { a = rotate_right_single(a); } else { a = rotate_right_double(a); } } return a; }
static PropPtr balance_node(PropPtr a) { int dh = height_diff(a); if (abs(dh) < 2) { fixup_height(a); } else { if (dh == 2) if (height_diff(AVL_RT(a)) >= 0) a = rotate_left_single(a); else a = rotate_left_double(a); else if (height_diff(AVL_LF(a)) <= 0) a = rotate_right_single(a); else a = rotate_right_double(a); } return a; }