For this project we're suppose to build a linked list and so far I've gotten most of it down due to the teacher helping write the code in class. What I'm having problems with is my push_front(). With the way the teacher showed us how to write it, I'm constantly writing over the node each time I want to add a new node onto the list. Here's my code for the push_front:
List groceryList;
// Create new Node object and push to front of list
groceryList.push_front(new Node("bread", "loaves", 2) );
groceryList.push_front(new Node("milk", "gallons", 2) );
groceryList.push_front(new Node("eggs", "dozen", 1) );
groceryList.push_front(new Node("oranges", "bag", 1) );
// PrintList()
void printList(const List& theList)
{
Node* currentNode = theList.getFirstNode();
while(currentNode != nullptr)
{
// Set nextNode ptr to the next Node
Node* nextNode = currentNode->getNextNode();
// Output the quantity, units, and description of currentNode
cout << currentNode->getQuantity() << ' ' << currentNode->getUnits() << " of " <<
currentNode->getDescription() << endl;
// Assign current node to the next Node in the list
currentNode = currentNode->getNextNode();
}
}