Adding a class object into a linked list

I seem to be stuck on these at the moment. Could someone help explain a function that adds an item into a linked list? Thanks!
For a simple linked-link, in which a node is composed of the data we care about and a pointer-to-a-node:

Get the node at the end of the existing list.
It has a pointer to a node, currently set to NULL - make it point to the new node we want to add to the end of the list.


Also make sure the pointer to next in that node points to NULL. The node will contain the object to wish to store.

Remember your list is limited to only one data type. The best way to declare this is to use a typedef at the very top of you list declaration.

For instance:

typedef MyClass T;


/// use T everywhere in your list
Remember your list is limited to only one data type.
With std::list, but with a custom list with a custom node you can fill it with as much data as you wish.

typedef MyClass T;
Why not just use a real template?
Last edited on
Topic archived. No new replies allowed.