Page 505, Exercise 4

 
void right_rotation(tree_pointer *parent, int *unbalanced)
{
  tree_pointer child, grand_child;
  child = (*parent)->right_child;
  if (child->bf == -1) {
  /* single rotation */
     printf("Single Right Rotation\n");
     (*parent)->right_child = child->left_child;
     child->left_child = *parent;
     (*parent)->bf = 0;
     *parent = child;
  }
  else {
  /* double rotation */
     printf("Double Right  Rotation \n");
     grand_child = child->left_child;
     child->left_child = grand_child->right_child;
     grand_child->right_child = child;
     (*parent)->right_child = grand_child->left_child;
     grand_child->left_child = *parent;
     switch (grand_child->bf) {
	case 1:  (*parent)->bf = 0;
		  child->bf = -1;
		  break;
	case 0:  (*parent)->bf =  child->bf = 0;
		  break;
	case -1: (*parent)->bf = 1;
		 child->bf = 0;
      }
      *parent = grand_child;
    }
    (*parent)->bf = 0;
    *unbalanced = FALSE;
}