I got my program to compile successfully without crashing, but is my code correct? Does it destroy all the links and avoid memory leaks/dangling pointers?
the comments are omitted segments of the program, i thought I had to de-link everything before I could delete the node?
I got my program to compile successfully without crashing, but is my code correct?
No, it's not. Your code exhibits undefined behavior because you delete the same objects twice.
The objects pointed to by head and tail at the beginning of the destructor are deleted through the current pointer. Then they are deleted again at the end of the destructor.
1 2 3 4 5 6 7 8 9 10 11
Double::~Double()
{
Dnode *current = head;
while (current)
{
Dnode* next = current->next;
delete current;
current = next;
}
}