Feature #11: Directory Iterator

Implementing the "Directory Iterator" feature for our "Operating System" project.

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 list nested_list.
  • next() returns the next file in the nested directories.
  • has_next() returns true if there are still some files in the nested list. If there are no files left in the nested list, it returns false.
Access this course and 1400+ top-rated courses and projects.