General AVL Insertion Method
Find the place to insert the new key. (While descending the tree, remember the last node having balance factor = -1 or +1. Call it A.)
If the key is already there, return.
Otherwise insert the new key. If there is no A, go down the path from the root to the new key again, updating balance factors, and then return.
Go back to A. If it had bf = 1 and the key went into its right subtree, or if it had bf = -1 and the key went into its left subtree, then set bf(A)=0, fix the bf values on the path from A to the new key, and return.
Otherwise, if A had bf = 1 and the new key went into its left subtree, then perform either a LL rotation or a LR rotation depending upon whether the key went into the left or right subtree of A’s left subtree.
If it had bf = -1 and the new key went into its right subtree, then perform either a RR rotation or a RL rotation depending upon whether the key went into the right or left subtree of A’s right subtree.
Fix the bf values of the nodes involved in the rotation.
Correct the bf values of the nodes on the path from A to the new key.