Solutions to other chapters:
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26  
Java Methods Home Page Skylight Publishing



Java Methods A & AB:
Object-Oriented Programming and Data Structures

Answers and Solutions to Exercises

Chapter 19

2.   public <E> void append(List<E> list1, List<E> list2) { for (int i = 0; i < list2.size(); i++) list1.add(list2.get(i)); }
6.   public double sum2(List<Double> list) { double sum = 0; ListIterator<Double> iter1 = list.listIterator(); while (iter1.hasNext()) { double a = iter1.next().doubleValue(); ListIterator<Double> iter2 = list.listIterator(iter1.nextIndex()); while (iter2.hasNext()) { sum += a * iter2.next().doubleValue(); } } return sum; }
8.  
Three-Two
Three-Two-One
Three-Two-One
10. (b) The following simplification uses Point's copy constructor: Point cursor; Stack<Point> stk = new Stack<Point>(); ... // Save cursor position: stk.push(new Point(cursor)); show(new LoginWindow()); ... // Restore cursor position: cursor = stk.pop(); Recall that a stack holds references to objects.  It is necessary to make and push a copy of cursor because subsequent code may change the original.
13.   0 2 1 3 2 4
21. (a) O(1)
(c) O(n)




Copyright © 2006 by Skylight Publishing