Linked list question...
I have a simple question.
How do you send the pointer back to the start of one's list after creating it..
I have this:
typedef struct myitem
struct myitem *next;
I use the function:
void slstore(struct myitem *i)
static struct myitem *last=NULL;
if(!last) last = i;
i->next = NULL;
last = i;
to store my items into the list..
I want to use
void display(struct myitem *top)
top = top->next;
But I guess I need to put the pointer back to the start of the list before calling display..
Any ideas on how to do that?
You need to create two items for that list: one to traverse though and one to hold the position of first item; ``myitem *head, *current;''
Now, never change the contents of head (only when you want to create/destroying the list). When you need to dig a specific node from the list do ``current = current->next;'' and jump to the beginning like ``current = head;''