예제 #1
0
파일: height.c 프로젝트: rumidier/Bit
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;
}
예제 #2
0
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");
}
예제 #3
0
//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;
}
예제 #4
0
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;
}	
예제 #5
0
파일: height.c 프로젝트: rumidier/Bit
NODE* rotate_RL (NODE *parent)
{
  NODE *child   = parent->right;
  parent->right  = rotate_LL(child);
  return rotate_RR(parent);
}
예제 #6
0
파일: height.c 프로젝트: rumidier/Bit
NODE* rotate_LR (NODE *parent)
{
  NODE *child   = parent->left;
  parent->left  = rotate_RR(child);
  return rotate_LL(parent);
}
예제 #7
0
AvlNode* rotate_LR(AvlNode *parent){
  AvlNode *child = parent->left_child;
  parent->left_child = rotate_RR(child);
  return rotate_LL(parent);
}
예제 #8
0
AvlNode* rotate_RL(AvlNode *parent){
  AvlNode *child = parent->right_child;
  parent->right_child = rotate_LL(child);
  return rotate_RR(parent);
}