Question
This problem mirrors Exercise E4.6. For each of the questions in that exercise, implement a client method (i.e., a method that is outside the List
This problem mirrors Exercise E4.6. For each of the questions in that exercise, implement a client method (i.e., a method that is outside the List class) with the following specifications:
(a) void empty(List L)
(b) void removeAll(List L, T item)
(c) int size(List L)
(d) boolean contains(List L, T item)
Exercise E4.6
Suppose you are given a list that supports only the operations append, remove, and enumerate, as described in the first three rows of Table 4.1. Give an algorithm describing how you would perform each of the following operations in terms of the given operations.
(a) Empty a list (i.e., remove all the entries)
(b) Remove all occurrences of a given item from a list
(c) Obtain the size (i.e., the number of entries) of a list
(d) Search for a given item in the list, returning true or false depending on whether the item is found or not
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started