Jul 30, 2012 at 9:06pm Jul 30, 2012 at 9:06pm UTC
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!
Jul 30, 2012 at 9:11pm Jul 30, 2012 at 9:11pm UTC
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.
Jul 31, 2012 at 3:47am Jul 31, 2012 at 3:47am UTC
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
Jul 31, 2012 at 4:17am Jul 31, 2012 at 4:17am UTC
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.
Why not just use a real template?
Last edited on Jul 31, 2012 at 4:17am Jul 31, 2012 at 4:17am UTC