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 NestedIterator class:

  • NestedIterator(std::vector<NestedDirectory *> nestedList) initializes the iterator with the nested list nestedList.
  • string next() returns the next file in the nested directories.
  • bool hasNext() 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.

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.