No I'm not asking about how to write one, I want to know about the data that the linked list stores. If I had a list with the following:
Code:
template<typename T>
class List {
private:
struct Node {
Node* prev;
Node* next;
T data;
};
Node* head;
Node* tail;
unsigned size;
...
Would this function destory the list?
Code:
void destoryList(void) {
Node* dest_h = head;
Node* dest_t = tail;
while(dest_h != 0) {
showData(&(dest_h->data), &(dest_t->data)); // This is a test func, ignore please
head = head->next;
tail = tail->prev;
delete dest_h;
delete dest_t;
dest_h = head;
dest_t = tail;
}
return;
}
If I had created the node by using the next pointer for every new node, everytime I attempt to delete a node I have to do delete on both it's prev and next pointers, I thought that delete would destory the entire Node. How does this work?
And what about the data? Once I use the function to delete all the prev and next pointers in the list, how would be data be deleted? Are the data on the stack? Even though the node is created dynamically?
Thanks for any help.