First Time w/ Linked List

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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void List::push_front(Node* p)
{
	if( firstNode = nullptr )
	{
		firstNode = p;
		lastNode = p;
	}
	else
	{
		p->setNextNode(lastNode);	
		firstNode = p;
	}
	numberOfNodes++;
}


and here's the code from my driver(incase I've declared something wrong):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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();
	}
}

Advice is appreciated. Thank you!
Use == for comparison.
Thanks. Didn't think about that one.
Topic archived. No new replies allowed.