Logo Data Structures and Algorithms with Object-Oriented Design Patterns in C++
next up previous contents index

Removing Items from an M-Way Search Tree

The procedure for removing items from an M-way search tree follows directly from the algorithm for removing items from a binary search tree given in Section gif. The basic idea is that the item to be deleted is pushed down the tree from its initial position to a node from which it can be easily deleted. Clearly, items are easily deleted from leaf nodes. In addition, consider an internal node of an M-way search tree of the form

displaymath65574

If both tex2html_wrap_inline64404 and tex2html_wrap_inline63460 are empty trees, then the key tex2html_wrap_inline64406 can be deleted from T by removing both tex2html_wrap_inline64406 and tex2html_wrap_inline63460, say. If tex2html_wrap_inline64404 is non-empty, tex2html_wrap_inline64406 can be pushed down the tree by swapping it with the largest key in tex2html_wrap_inline64404; and if tex2html_wrap_inline63460 is non-empty, tex2html_wrap_inline64406 can be pushed down the tree by swapping it with the smallest key in tex2html_wrap_inline63460.

Program gif gives the code for the Withdraw function of the MWayTree class. The general form of the algorithm follows that of the Withdraw routine for the BST class (Program gif).

   program21665
Program: MWayTree Class Withdraw Member Function Definition


next up previous contents index

Bruno Copyright © 1997 by Bruno R. Preiss, P.Eng. All rights reserved.