The Withdraw function can be used to
remove items from a list one at a time.
Suppose we want to provide an additional a member function,
WithdrawAll,
that takes one argument and withdraws all the items in a list
that match the given argument.
We can provide an abstract implementation of the WithdrawAll
function in the List class like this:
void List::WithdrawAll (Object const& arg)
{
for (;;)
{
Object& object = Find (arg);
if (object.IsNull ())
break;
Withdraw (object);
}
}
Determine the worst-case running time of this routine
for each of the following cases:
- an array-based implementation of an ordered list,
- a linked-list implementation of an ordered list,
- an array-based implementation of a sorted list, and
- a linked-list implementation of a sorted list.