14.5.1 Step 2: Delete [ToC] [Index]     [Skip Fwd]     [Prev] [Up] [Next]

The actual deletion step is derived from that for PBSTs. We add code to modify balance factors and set up for rebalancing. After the deletion, q is the node at which balance factors must be updated and possible rebalancing occurs and dir is the side of q from which the node was deleted. This follows the pattern already seen in TAVL deletion (see Deleting a TAVL Node Step 2 - Delete).

537. <Step 2: Delete item from PAVL tree 537> =
if (p->pavl_link[1] == NULL)
  { 
    <Case 1 in PAVL deletion 538>
  } else
  { struct pavl_node *r = p->pavl_link[1]; if (r->pavl_link[0] == NULL) {
        <Case 2 in PAVL deletion 539>
      } else
      {
        <Case 3 in PAVL deletion 540>
      } } tree->pavl_alloc->libavl_free (tree->pavl_alloc, p);

This code is included in 536.

Case 1: p has no right child

No changes are needed for case 1. No balance factors need change and q and dir are already set up correctly.

538. <Case 1 in PAVL deletion 538> =
<Case 1 in PBST deletion; pbst => pavl 499>

This code is included in 537.

Case 2: p's right child has no left child

See the commentary on <Case 3 in TAVL deletion 318> for details.

539. <Case 2 in PAVL deletion 539> =
<Case 2 in PBST deletion; pbst => pavl 500>
r->pavl_balance = p->pavl_balance;
q = r;
dir = 1;

This code is included in 537.

Case 3: p's right child has a left child

See the commentary on <Case 4 in TAVL deletion 319> for details.

540. <Case 3 in PAVL deletion 540> =
<Case 3 in PBST deletion; pbst => pavl 501>
s->pavl_balance = p->pavl_balance;
q = r;
dir = 0;

This code is included in 537.