14.5.1 Step 2: Delete |
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).
535. <Step 2: Delete item from PAVL tree 535> = if (p->pavl_link[1] == NULL) {
<Case 1 in PAVL deletion 536>
} else
{ struct pavl_node *r = p->pavl_link[1]; if (r->pavl_link[0] == NULL) {
<Case 2 in PAVL deletion 537>
} else
{
<Case 3 in PAVL deletion 538>
} } tree->pavl_alloc->libavl_free (tree->pavl_alloc, p);
This code is included in 534.
No changes are needed for case 1. No balance factors need change and q and dir are already set up correctly.
536. <Case 1 in PAVL deletion 536> = <Case 1 in PBST deletion; pbst => pavl 497>
This code is included in 535.
See the commentary on <Case 3 in TAVL deletion 316> for details.
537. <Case 2 in PAVL deletion 537> = <Case 2 in PBST deletion; pbst => pavl 498> r->pavl_balance = p->pavl_balance; q = r; dir = 1;
This code is included in 535.
See the commentary on <Case 4 in TAVL deletion 317> for details.
538. <Case 3 in PAVL deletion 538> = <Case 3 in PBST deletion; pbst => pavl 499> s->pavl_balance = p->pavl_balance; q = r; dir = 0;
This code is included in 535.