This is a frequent problem I encounter and I want to be able to figure out what is actually going on.
I have a node class that has char and char* private members.
When I am trying to delete a node, the node actually goes away, but the nodes that follow the deleted node get corrupted. Both the char and char* data in the node is gibberish or NULL. They don't go away, as there are correct number of nodes after the delete, but the data inside nodes are acting up.
I know that the problem is something to do with the head = temp statement. I thought this was a safe copy method between two pointers.
Can you see what is going on ? How can I better deal with this.
TAKEN FROM A RECURSIVE FUNCTION
1 2 3 4 5 6 7 8 9 10
node*temp = head->next_node(); // Assign temp to next pointer
temp->node_display();// Temp Points to the correct node
delete head;
head = temp; // Problem starts after this line
head->node_display(); // Node is now corrupted.
return;