8.4.3 Symmetric Case [ToC] [Index]     [Skip Back]     [Prev] [Up] [Next]

Here is the corresponding code for the case where insertion occurs in the right subtree of y.

310. <Rebalance TAVL tree after insertion in right subtree 310> =
struct tavl_node *x = y->tavl_link[1];
if (x->tavl_balance == +1)
  { 
    <Rebalance for + balance factor in TAVL insertion in right subtree 311>
  } else
  {
    <Rebalance for - balance factor in TAVL insertion in right subtree 312>
  }

This code is included in 306.

311. <Rebalance for + balance factor in TAVL insertion in right subtree 311> =
w = x;
if (x->tavl_tag[0] == TAVL_THREAD) 
  { x->tavl_tag[0] = TAVL_CHILD; y->tavl_tag[1] = TAVL_THREAD; y->tavl_link[1] = x; } else
  y->tavl_link[1] = x->tavl_link[0]; x->tavl_link[0] = y; x->tavl_balance = y->tavl_balance = 0;

This code is included in 310.

312. <Rebalance for - balance factor in TAVL insertion in right subtree 312> =
<Rotate right at x then left at y in AVL tree; avl => tavl 161>
if (w->tavl_tag[0] == TAVL_THREAD) 
  { y->tavl_tag[1] = TAVL_THREAD; y->tavl_link[1] = w; w->tavl_tag[0] = TAVL_CHILD; } if (w->tavl_tag[1] == TAVL_THREAD)
  { x->tavl_tag[0] = TAVL_THREAD; x->tavl_link[0] = w; w->tavl_tag[1] = TAVL_CHILD; }

This code is included in 310, 322, and 668.