-
delete last node
Hey guys im trying to delete the last node in a doubly linked list so far i have traversed and found the end using a while loop then making PREVIOUS which is now the last one to equal NULL. Then i am freeing the node that i have malloced would this work for a doubly linked list?
Code:
while(current->next !=NULL)
{
previous = current;
current = current->next;
}
previous->next = NULL
free(current)
-
Yes. Did you even think about the problem before asking here ? I mean this is probably your 5th thread about the same easy data structure and for every problem there is, you create a new topic and ask the same mindless questions instead of using your brain and coming up with the solution yourself.
-
Yes. You don't have to worry about any pointers other than previous->next because you're deleting the last node and don't have to update any back pointers.
-
I was only asking if this was correct i may not be a genious but i am trying and i only ask for advice on how to approach it
-
Thanks Noir thats what i thought