Question: Listing 20.7, DirectorySize.java, gives a recursive method for finding a directory size. Rewrite this method without using recursion. Your program should use a queue to
Listing 20.7, DirectorySize.java, gives a recursive method for finding a directory size. Rewrite this method without using recursion. Your program should use a queue to store the subdirectories under a directory. The algorithm can be described as follows:


long getSize (File directory) { long size = 0; add directory to the queue; while (queue is not empty) { Remove an item from the queue into t; if (t is a file) size += t.1ength(); else add all the files and subdirectories under t into the queue; return size;
Step by Step Solution
3.41 Rating (151 Votes )
There are 3 Steps involved in it
Program Plan Create class DirectorySize It contains two method which are mainString args and getSize... View full answer
Get step-by-step solutions from verified subject matter experts
