Doubly Linked List - Storing Data

Hi,

I am constructing a doubly linked list for a class project. It is slowly coming along but I have hit a bit of a wall in my google searching. I'd appreciate any assistance.

Currently, from what I understand I am wanting to store a class in the node but I am a bit unsure how to pass the class through to the node.

Here is what I have gotten so far:

1
2
PLanguage newLanguage(); //Declare new language
languageList.addFront(const PLanguage& newLanguage); // Create node at front of list with language 


1
2
3
4
5
6
7
void DoublyLinkedList::addFront(const PLanguage& x)
{
	Node* tempNode = new Node;			// Create new node.
	tempNode->language = x;					// Store data.
	tempNode->next = head;				// Current head is now next of our new node.
	head = tempNode;					// Our new node is now the new head.
}


I am trying to pass the object to the function as the x variable.

Am I incorrect in thinking it is the class object we are wanting to assign to language? Maybe just the name of the class?

Thank you for your help.
You are correct. Line 4 will copy the content of x to tempNode->language.

Note that problems with shallow copy may arise (if PLanguage contains pointer):

http://www.learncpp.com/cpp-tutorial/915-shallow-vs-deep-copying/
Topic archived. No new replies allowed.