The withdraw method can be used to
remove items from a list one at a time.
Suppose we want to provide an additional a method,
withdrawAll,
that takes one argument and withdraws all the items in a list
that match the given argument.
We can provide an implementation of the withdrawAll
method in the AbstractSearchableContainer class like this:
public class AbstractSearchableContainer
extends AbstractContainer
implements SearchableContainer
{
void withdrawAll (Comparable arg)
{
Comparable object;
while ((object = Find (arg)) != null)
withdraw (object);
}
// ...
}
Determine the worst-case running time of this method
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.