Problems

17.17

Write a program that, given a directory, lists the contents of that directory and any subdirectories. The output should be nicely formatted, with files deeper in the directory structure indented farther. (Hint: Look at the API for the File class.)

17.18

Modify the ExternalSort program so that it sorts files of ints (in binary format) rather than lines of text.

17.19

There is a subtle flaw in the IdGenerator class (Figure 17-44): if we use it many times, the counter in the file will "wrap around" to negative numbers, and then back to 0. Eventually it will begin handing out ids that have been generated before and that might still be in use. Modify the class to keep a set of in-use ids in the file. The nextId() method should never return an in-use id. Modify the deleteFromDisk() method of the BTreeNode class to inform the IdGenerator when an id number is no longer in use.

Категории