Hi guys/girls. I'm trying to delete a node from the end of a Linked List but I have some problems.
Every node has it's unique code.
Here is what I do:
1. Ask the user for the unique code of the node.
2. Ask him if he wants to change the data in it or delete the whole node.
3. If he chooses to delete it, I do this:
1 2 3 4
//let's say that temp1 points to the node
List *temp2 = temp1;
temp1 = temp1->next;
delete temp2;
And it's just not deleting the node. I'm trying to solve this problem all day but without result. Does anybody know where I have made a mistake?
You're not doing anything to remove a node in the list, you're just taking one node in the middle of the list and turning it into garbage.
Let's say for a general case that you have a list with at least 4 nodes in it. Say you want to take node 3 out of a list. You must first make node 2's "next" point to node 4 now. That's how you 'remove' a node from the list. Once you do that, you can delete node 3.