I'm still having trouble figuring out how to keep track of my linked lists but have come up with some progress.
My code is reading the data from the text file perfectly through the nodes but I cannot seem to figure out how to transfer it properly to the show function to show all the nodes.
READING FROM FILE (not working correctly)
void insertAsFirstElement(ifstream& budgetFile, budgetItem *&head, budgetItem *&last, int number, int& counter)
{
int ctype;
string cname;
double camount;
char clearOrNot;
while (!budgetFile.eof())
{
budgetItem *temp = new budgetItem;
budgetFile >> ctype >> cname >> camount >> clearOrNot;
temp->theType = ctype;
cout << temp->theType << endl;
//cout << ctype << endl;
temp->name = cname;
cout << temp->name << endl;
temp->amount = camount;
cout << temp->amount << endl;
if (clearOrNot == 'Y')
{
temp->cleared = true;
}
else
{
temp->cleared = false;
}
last = temp;
temp->next = NULL;
if (counter == 0)
{
//head = temp;
head = temp;
}
counter++;
}
}
SHOWING THE DATA IN THE NODES (only one node's data is showing...) *I need all the nodes and all their data showing.(must have something to do with reading)
void showList(budgetItem *current)
{
if (isEmpty(current)) {
cout << "The list is empty." << endl;
}
else
{
cout << "The list contains: " << endl;
while (current != NULL)
{
cout << current->theType << " ";
cout << current->name << " ";
cout << current->amount << " ";
cout << current->cleared << endl;
current = current->next;
}
}
}