NODE *balance_tree (NODE **node) { int height_diff; height_diff = get_balance(*node); printf("밸런스값 %d\n", height_diff); if (height_diff > 1) { if (get_balance((*node)->left) > 0) { *node = rotate_LL(*node); }else { *node = rotate_LR(*node); } } else if (height_diff < -1) { if (get_balance((*node)->right) < 0) { *node = rotate_RR(*node); } else { *node = rotate_LL(*node); } } return *node; }
void do_rotation(ROOT *r, int rotation_type) { if(rotation_type == 1) rotate_LL(r); else if(rotation_type == 2) rotate_RL(r); else if(rotation_type == 3) rotate_LR(r); else if(rotation_type == 4) rotate_RR(r); else printf("invalid rotation type \n"); }
//balancing AvlNode* rebalance(AvlNode **node){ int height_diff = get_height_diff(*node); if( height_diff > 1){ if(get_height_diff((*node)->left_child) > 0) *node = rotate_LL(*node); else *node = rotate_LR(*node); } else if(height_diff<-1){ if(get_height_diff((*node)->right_child) < 0) *node = rotate_RR(*node); else *node = rotate_RL(*node); } return *node; }
NODE *balance_tree(NODE **node){ int height_diff; height_diff = get_balance(*node); printf("밸런스 값 : %d\n", height_diff); if(height_diff > 1){ if(get_balance((*node)->left) > 0) *node = rotate_LL(node); else *node = rotate_LR(node); } else if(height_diff <-1){ if(get_balance((*node)->left) >0) *node = rotate_RR(node); else *node = rotate_RL(node); } return *node; }
NODE* rotate_RL (NODE *parent) { NODE *child = parent->right; parent->right = rotate_LL(child); return rotate_RR(parent); }
NODE* rotate_LR (NODE *parent) { NODE *child = parent->left; parent->left = rotate_RR(child); return rotate_LL(parent); }
AvlNode* rotate_LR(AvlNode *parent){ AvlNode *child = parent->left_child; parent->left_child = rotate_RR(child); return rotate_LL(parent); }
AvlNode* rotate_RL(AvlNode *parent){ AvlNode *child = parent->right_child; parent->right_child = rotate_LL(child); return rotate_RR(parent); }