Java Reference
In-Depth Information
΢΢΢Exercise P14.10. Implement the sort method of the merge sort
algorithm without recursion, where the length of the array is an arbitrary
number. Keep merging adjacent regions whose size is a power of 2, and
pay special attention to the last area whose size is less.
΢΢΢Exercise P14.11. Use insertion sort and the binary search from Exercise
P14.8 to sort an array as described in Exercise R14.14. Implement this
algorithm and measure its performance.
΢ Exercise P14.12. Supply a class Person that implements the
Comparable interface. Compare persons by their names. Ask the user to
input 10 names and generate 10 Person objects. Using the compareTo
method, determine the first and last person among them and print them.
΢΢Exercise P14.13. Sort an array list of strings by increasing length. Hint:
Supply a Comparator .
΢΢΢Exercise P14.14. Sort an array list of strings by increasing length, and so
that strings of the same length are sorted lexicographically. Hint: Supply
a Comparator .
Additional programming exercises are available in WileyPLUS.
662
663
PROGRAMMING PROJECTS
΢΢΢Project 14.1. Write a program that keeps an appointment book. Make a
class Appoi ntment that stores a description of the appointment, the
appointment day, the starting time, and the ending time. Your program
should keep the appointments in a sorted array list. Users can add
appointments and print out all appointments for a given day. When a
new appointment is added, use binary search to find where it should be
inserted in the array list. Do not add it if it conflicts with another
appointment.
΢΢΢GProject 14.2. Implement a graphical animation of sorting and
searching algorithms. Fill an array with a set of random numbers
between 1 and 100. Draw each array element as a bar, as in Figure 3 .
Search WWH ::




Custom Search