Non-recursive way to list files in directory and subdirectories without using stack/queue
During an interview, I was asked to list the names of files in a directory and its subdirectories¹ without using neither recursion, nor stack or queue.

Since the only non-recursive way I know uses a stack, I was unable to answer this question.

The interviewer explained the solution, but I was unable to understand it. The only thing I remember is that it involved two methods instead of one.

What is this approach which allows listing files in a directory and its subdirectories with no recursion and no stack or queue?

---

<sup>¹ The solution is language agnostic. The list of subdirectories is provided by a `ListDirectories(string directoryPath)` method, and the files - by `ListFiles(string directoryPath)`. We don't know in advance the depth of subdirectories.</sup>
Non-recursive way to list files in directory and subdirectories without using stack/queue
===

During an interview, I was asked to list the names of files in a directory and its subdirectories¹ without using neither recursion, nor stack or queue.

Since the only non-recursive way I know uses a stack, I was unable to answer this question.

The interviewer explained the solution, but I was unable to understand it. The only thing I remember is that it involved two methods instead of one.

What is this approach which allows listing files in a directory and its subdirectories with no recursion and no stack or queue?

---

<sup>¹ The solution is language agnostic. The list of subdirectories is provided by a `ListDirectories(string directoryPath)` method, and the files - by `ListFiles(string directoryPath)`. We don't know in advance the depth of subdirectories.</sup>