Java Reference
In-Depth Information
΢ Exercise P17.2. Add a method swap to the Pair class of Exercise P17.1
that swaps the first and second elements of the pair.
΢΢ Exercise P17.3. Implement a static generic method PairUtil.swap
whose parameter is a Pair object, using the generic class defined in
Section 17.2 . The method should return a new pair, with the first and
second element swapped.
΢΢ Exercise P17.4. Write a static generic method PairUtil.minmax that
computes the minimum and maximum elements of an array of type T and
returns a pair containing the minimum and maximum value. Require that
the array elements implement the Measurable interface of Chapter 9 .
΢΢ Exercise P17.5. Repeat the problem of Exercise P17.4, but require that the
array elements implement the Comparable interface.
΢΢΢ Exercise P17.6. Repeat the problem of Exercise P17.5, but refine the
bound of the type variable to extend the generic Comparable type.
΢΢ Exercise P17.7. Implement a generic version of the binary search
algorithm.
΢΢΢ Exercise P17.8. Implement a generic version of the merge sort
algorithm. Your program should compile without warnings.
΢΢ Exercise P17.9. Implement a generic version of the
BinarySearchTree class of Chapter 16 .
΢΢ Exercise P17.10. Turn the HashSet implementation of Chapter 16 into a
generic class. Use an array list instead of an array to store the buckets.
΢΢ Exercise P17.11. Define suitable hashCode and equals methods for
the Pair class of Section 17.2 and implement a HashMap class, using a
HashSet<Pair<K, V>> .
΢΢΢ Exercise P17.12. Implement a generic version of the permutation
generator in Section 13.2 . Generate all permutations of a List<E> .
Search WWH ::




Custom Search