I'm trying to understand the following piece of code for AVL trees, but am having some difficulty. I know that if the tree is left heavy, it will do a right rotation. Same goes if it's right heavy, it will do a left rotation. Appreciate if someone could explain or point me in the right direction in understanding the below code.
static void avl_rotate_right(TLDList *tld, TLDNode *node) {
if (node->parent != NULL) {
if (node->parent->left == node)
node->parent->left = node->left;
else
node->parent->right = node->left;
} else
tld->root = node->left;
node->left->parent = node->parent;
node->parent = node->left;
node->left = node->left->right;
if (node->left != NULL)
node->left->parent = node;
node->parent->right = node;
}