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 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 lines of this code is broken...
#include
#include
#include
#include
using namespace std;
class Node
public:
string category;
string line;
Node next;
Nodeconst string& category, const string& line
: categorycategory lineline nextnullptr
;
class LinkedList
private:
Node headPtr;
public:
LinkedList : headPtrnullptr
~LinkedList;
void addNodeconst string& category, const string& line;
void displayList;
vector toVector;
;
LinkedList::~LinkedList
while headPtr nullptr
Node temp headPtr;
headPtr headPtrnext;
delete temp;
void LinkedList::addNodeconst string& category, const string& line
Node newNode new Nodecategory line;
if headPtr nullptr category headPtrcategory
category headPtrcategory && line headPtrline
newNodenext headPtr;
headPtr newNode;
return;
Node curPtr headPtr;
while curPtrnext nullptr &&
category curPtrnextcategory
category curPtrnextcategory && line curPtrnextline
curPtr curPtrnext;
newNodenext curPtrnext;
curPtrnext newNode;
void LinkedList::displayList
Node curPtr headPtr;
while curPtr nullptr
cout curPtrline endl;
curPtr curPtrnext;
vector LinkedList::toVector
vector result;
Node curPtr headPtr;
while curPtr nullptr
result.pushbackcurPtrcategory;
result.pushbackcurPtrline;
curPtr curPtrnext;
return result;
int main
LinkedList categories;
string filename inputtxt; Change this to your input file name
cout "Enter the file name: ;
cin filename;
ifstream inputFilefilename;
if inputFile
cerr "Error opening file filename endl;
return ;
string category, line;
while getlineinputFile line
if lineempty continue;
int delimiterIndex line.find:;
if delimiterIndex string::npos continue;
category line.substr delimiterIndex;
line line.substrdelimiterIndex ;
for int i ; i ; i
if categoriesiheadPtr && categoriesiheadPtrcategory category
categoriesiaddNodecategory line;
break;
inputFile.close;
for int i ; i ; i
if categoriesiheadPtr
cout categoriesiheadPtrcategory : endl;
vector lines categoriesitoVector;
for int j ; j lines.size; j
cout linesj endl;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
