I want to add item to a linked list (course object).
course* start = ....; // course pointer as start of list
course* c = ....; // another course object pointer to add to list
Then to add to the list, I use:
course* temp = start; // copy start current value to a temp object
start = c; // set start value to newest object
c->next = temp; // linked back to previous object
return start; // return result
That works, but now I want to wrap that into a function named addToEnd():
addToEnd(start, c);
with
void addToEnd(course* start, course* c)
{
// LIFO
course* temp = start; // copy start current value to a temp object
start = c; // set start value to newest object
c->next = temp; // linked back to previous object
}
The change occurs only inside the function, and has no effect outside. What have I done wrong?
And NO! My question is different from the suggested 'LinkedList C++ implementation' question.