Feel free to edit the title, engrish can sometimes confuse instead of help.
I have to make (and no I can’t change, this is the way it has to be) simple linked list. NO I can’t use STL or std::list. Most of it is done, on paper, but I seem to have a problem implementing a very basic cursor.
This is my Node within the list (part of it):
struct Node {
int ap_nr;
Node *next;
};
I want to go trough the list in my add node function:
void add_node (Node **begin, int ap_nr)
{
stuff happens
}
This is how I call the function:
add_node(&(*begin), ap_nr);
I want to create a cursor that starts from begin (the head of my list) and goes trough every node using cursor->next until I reach the end (while (cursor->next!=0))
but I can’t simply say:
Node *cursor;
cursor = new Node;
cursor = begin;
Because this will simply overwrite cursor with begin, making my attempt invalid. I still have to make a pointer to begin and be able to call the STRUCT function “-> next”
How can I do this ?
* ALSO * How can I remember the previous Node ? can I do this:
Node *previous;
previous = new Node;
previous = &(*begin); // ?
It sounds like you want to traverse the list in the
add_nodefunction. If so then try the followingNote: To call this function initially you should just call it with
add_node(&theListPointer).