576
b.A Boolean instance method named greaterFoundthat receives a single argu-
ment,item, and searches the list for a value greater than item. If such a value
is found, the method returns true; otherwise, it returns false.
c. An instance method named componentthat returns a component of the list
given a position number (pos). The position number must be within the
range 0 through numItems– 1.
d.A copy constructor for theListclass that takes an argument that specifies
how much to expand the array holding the items. Implement the copy
constructor by creating a larger array and copying all of the items in the list
into the new array.
4.Complete the implementation of SortedList as a class derived from the abstract
class List.
5.Derive a subclass of SortedListthat has the additional methods outlined in
Programming Warm-Up Exercise 3.
6.Write a Java Boolean method named exclusivethat takes three arguments:
item,list1, and list2(both of class Listas defined in this chapter). The method
returns trueif itemis present in either list1or list2but not both.
7.The insertmethod in the class SortedListinserts items into the list in ascend-
ing order. Derive a new class from Listthat sorts the items into descending
order.
8.Exam Preparation Exercise 14 asked you to examine the implication of a list
with duplicates.
a.Design an abstract class ListWithDuplicatesthat allows duplicate keys.
b.How does your design differ from List?
c. Implement your design where the items are unsorted and deletedeletes all
of the duplicate items.
d.Implement your design where the items are sorted anddeletedeletes all of
the duplicate items.
e.Did you use a binary search in part (d)? If not, why not?
9.Rewrite the method insertin the class SortedListso that it implements the
first insertion algorithm discussed for sorted lists. That is, the place where the
item should be inserted is found by searching from the beginning of the list.
When the place is found, all of the items from the insertion point to the end of
the list shift down by one position.