Hi packetpirate.
A link list can be made with a single node*. A pointer to the head node is adequate, especially if the desired operation for adding nodes is to push_front. Karajics function name
addHeadNode suggests to me that he is trying to add nodes to the front of the list.
A pointer to the tail of the list is useful if a push_back operation is desired but is not absolutely necessary. Although inefficient, one
can reach the tail node by iterating to it from the head.
I was trying to correct the problem with adding to the front of the list.
I could give a complete implementation here but I think it would be bad for me to do that because this is a homework assignment for Karajic. I'd be happy to PM you an example if you wish. I've written many examples of various types of linked lists (they make a fun puzzle).
A couple of problems I see with your list of steps:
2. Pass the first and last nodes, as well as the new data as parameters. |
Perhaps mention that they should be passed by reference so the values of the pointers may be changed.
3. Create a temporary node pointer and assign the new data. Set the next pointer to NULL. |
This is OK but a node should be allocated to the pointer before any assignments are made.
EDIT: This may all be for naught though, as it appears that Karajic has received the desired help (a complete solution was posted) in his duplicate thread on this subject.
http://www.cplusplus.com/forum/general/52230/#msg283554