Question: Can you please share how you enter your data? because for me do not print and information for this code. From line 9 6 till

Can you please share how you enter your data? because for me do not print and information for this code.
From line 96 till the end, the code is not correct. HeadPtr can not be used, it because it is: 'headPtr' is a private member of 'LinkedList'. Anyway the last 20 lines of this code is broken...
#include
#include
#include
#include
using namespace std;
class Node {
public:
string category;
string line;
Node* next;
Node(const string& category, const string& line)
: category(category), line(line), next(nullptr){}
};
class LinkedList {
private:
Node* headPtr;
public:
LinkedList() : headPtr(nullptr){}
~LinkedList();
void addNode(const string& category, const string& line);
void displayList();
vector toVector();
};
LinkedList::~LinkedList(){
while (headPtr != nullptr){
Node* temp = headPtr;
headPtr = headPtr->next;
delete temp;
}
}
void LinkedList::addNode(const string& category, const string& line){
Node* newNode = new Node(category, line);
if (headPtr == nullptr || category headPtr->category ||
(category == headPtr->category && line = headPtr->line)){
newNode->next = headPtr;
headPtr = newNode;
return;
}
Node* curPtr = headPtr;
while (curPtr->next != nullptr &&
(category > curPtr->next->category ||
(category == curPtr->next->category && line > curPtr->next->line))){
curPtr = curPtr->next;
}
newNode->next = curPtr->next;
curPtr->next = newNode;
}
void LinkedList::displayList(){
Node* curPtr = headPtr;
while (curPtr != nullptr){
cout curPtr->line endl;
curPtr = curPtr->next;
}
}
vector LinkedList::toVector(){
vector result;
Node* curPtr = headPtr;
while (curPtr != nullptr){
result.push_back(curPtr->category);
result.push_back(curPtr->line);
curPtr = curPtr->next;
}
return result;
}
int main(){
LinkedList categories[5];
string filename ="/input.txt"; // Change this to your input file name
// cout "Enter the file name: ";
// cin >> filename;
ifstream inputFile(filename);
if (!inputFile){
cerr "Error opening file " filename endl;
return 1;
}
string category, line;
while (getline(inputFile, line)){
if (line.empty()) continue;
int delimiterIndex = line.find(':');
if (delimiterIndex == string::npos) continue;
category = line.substr(0, delimiterIndex);
line = line.substr(delimiterIndex +1);
for (int i =0; i 5; i++){
if (categories[i].headPtr && categories[i].headPtr->category == category){
categories[i].addNode(category, line);
break;
}
}
}
inputFile.close();
for (int i =0; i 5; i++){
if (categories[i].headPtr){
cout categories[i].headPtr->category ":" endl;
vector lines = categories[i].toVector();
for (int j =1; j lines.size(); j +=2){
cout "" lines[j] endl;
}
}
}
return 0;
}
Can you please share how you enter your data?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!