Here is the corresponding code for the case where insertion occurs in
the right subtree of y.
308. <Rebalance TAVL tree after insertion in right subtree 308> =
struct tavl_node *x = y->tavl_link[1];
if (x->tavl_balance == +1)
{
<Rebalance for + balance factor in TAVL insertion in right subtree 309>
}
else
{
<Rebalance for - balance factor in TAVL insertion in right subtree 310>
}
This code is included in 304.
309. <Rebalance for + balance factor in TAVL insertion in right subtree 309> =
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 308.
310. <Rebalance for - balance factor in TAVL insertion in right subtree 310> =
<Rotate right at x then left at y in AVL tree; avl => tavl 159>
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;
}
8.4.2 Step 4: Rebalance
|
8.4 Insertion
|
8.5 Deletion
|