I find the bug for this codes now. The right/left rotation functions use pointer to pointer. When I pass the parent’s l or r pointer to it. It cause a bug inside the function. A better way to improve this code is replace pointer to pointer by just pointer and update pointer by returning value.
solved Why these two C pointers set to NULL after one line code?