I'm overall kind of confused about the idea of linked lists. So I'm trying to implement some functions to help me understand.
struct Node {
string val;
Node* next;
Node* prev;
};
struct Stew {
Node* first;
Node* last;
};
So here, Stew has special pointers to the front element and the last element.
I'm trying to remove the first element (pop).
So I attempted it as follows, and I can't seem to find what the error in it is:
void pop (Stew& q) {
assert (!isEmpty(q));
q.first = q.first->next;
q.first -> prev = NULL;
}
Any help would be appreciated, thank you!
By the way, I'm currently using C++98, not C++11.
popfunction within your linked list class?popfunction should remove the first item from the list and return it, right now you are just losing this item, having no pointer to it and no way to use it or free the memory it uses.