The purpose of the LinkedListProcessor
class is to process text files by inserting each line from the file into dynamically generated line-linked-lists.
filePath
: The path of the file.fileReader
: An instance of theFileReader
class which job is to read the specified file.masterList
: An instance of theMasterLinkedList
class for inserting lines-linked-lists.
LinkedListProcessor()
: a default constructor with the default file path "../assets/data.txt" and creates an instance of theFileReader
.LinkedListProcessor(const string &filePath)
: Initializes aLinkedListProcessor
object with the provided file path and creates an instance of theFileReader
.
-
processFile()
:- Reads the file and puts each line into a list.
- If a line is empty, it skips it.
- After reading, it organizes the lines in a master list.
-
getMasterList()
:- Returns the
MasterLinkedList
containing the data from the processed file.
- Returns the
#include "LinkedListProcessor.h" // Ensure the path to `LinkedListProcessor.h` is correct
int main() {
LinkedListProcessor processor("path/to/file.extension");
processor.processFile();
MasterLinkedList masterList = processor.getMasterList();
return 0;
}
FileReader
: TheLinkedListProcessor
class relies on theFileReader
class for reading files.LineLinkedList
: TheLinkedListProcessor
class uses theLineLinkedList
class to organize lines of text.MasterLinkedList
: TheLinkedListProcessor
class using theMasterLinkedList
class to manage linked lists of lines.
-
How does the
processFile()
function work?- The
processFile()
function reads the content of the file, extracts words from each line, and stores them in correspondingLineLinkedList
objects. It then inserts theseLineLinkedList
objects into aMasterLinkedList
, organizing the file content into a hierarchical structure.
- The
-
Inside the
processFile
method, why do not use avector
insted thepointer dynamic array
:- When the size is known and fixed, and the need is only for a basic array functionality, using a static array (
LineLinkedList* lineListArray = new LineLinkedList[size];
) may be more efficient for both space and time complexity compared to using a vector (vector<LineLinkedList> lineList;
). Static arrays haveO(1)
access time and allocate only the necessary space, while vectors have additional overhead for capacity management and resizing.
- When the size is known and fixed, and the need is only for a basic array functionality, using a static array (