Feature #11: Directory Iterator
Implementing the "Directory Iterator" feature for our "Operating System" project.
We'll cover the following
Description
In this feature, we will create a directory tree iterator. A directory can contain files or other directories. Similarly, subdirectories can contain both files and other directories. We will be given a directory structure for a specific directory in the file system. This directory will be available as a list. Each element of this list is either a file represented as a scalar element, or a directory represented as a nested list. We will have to iterate over all of the files one by one, using an iterator.
The task is to implement the DirectoryIterator
class:
initialize(nested_list)
initializes the iterator with the nested listnested_list
.next()
returns the next file in the nested directories.has_next()
returnstrue
if there are still some files in the nested list. If there are no files left in the nested list, it returnsfalse
.
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.