575
2.Repeat Exercise 1, applying the algorithm for a sequential search in a sorted
list.
3.The following values are stored in an array in ascending order:
29 57 63 72 79 83 96 104 114 136
Apply the binary search algorithm looking for 114 in this list, and trace the val-
ues of first,last, and middle. Indicate any undefined values with a U.
4.A binary search is always a better choice than a sequential search. (True or
False?)
5.If resetListinitializes currentPosto 1 rather than 0, what corresponding
change would have to be made in getNextItem?
6.We have said that arrays are homogeneous structures, yet Java implements
them with an associated integer. Explain.
7.Why does the outer loop of the sorting method run from 0 through numItems – 2
rather than numItems – 1?
8.A method that returns the number of days in a month is an example of (a) a
constructor, (b) an observer, (c) an iterator, or (d) a transformer.
9.A method that adds a constant to the salary of everyone in a list is an example
of (a) a constructor, (b) an observer, (c) an iterator, or (d) a transformer.
10.A method that stores values into a list is an example of (a) a constructor, (b) an
observer, (c) an iterator, or (d) a transformer.
11.What Java construct is implemented using the keyword implements?
12.What kind of class cannot be instantiated?
13.Which interface contains the method compareTo? What does compareToreturn?
14.The class Listassumes that no duplicate items appear in the list.
a.Which method algorithms would have to be changed to allow duplicates?
b.Would there still be options for the deleteoperation? Explain.
Programming Warm-Up Exercises
1.Complete the implementation of UnsortedListas a class derived from the
abstract class List.
2.Complete the implementation of ListWithSortas a class derived from
UnsortedList.
3.Derive a subclass of UnsortedListthat has the following additional methods.
a.A value-returning instance method named occurrencesthat receives a single
parameter,item, and returns the number of times itemoccurs in the list.