In Robert Sedgewick's Algorithms book there's this exercise:
A folder is a list of files and folders. Write a program that takes the name of a folder as a command-line argument and prints out all of the files contained in that folder, with the contents of each folder recursively listed (indented) under that folder’s name. Hint: Use a queue.
Now I don't understand why I should use a queue for this. I can directly print it without first adding to the queue and dequeuing it later. Does it have any benefit that I cannot spot or is it just to strengthen my skills working with queues?
UPDATE: After so many answers and comments, I'm still confused as to how to print folders and files and subfolders the way the author wants. Please, could someone tell me if he wants something like this:
root folder1 folder2 file3.txt folder4 folder1_1 file1_1.txt folder2_1 file4_1.txt folder1_1_1 file2_1_1.txt
If that's the case, then
What Is Silly In Displaying Files This Way?