Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1
From https://www.geeksforgeeks.org/linked-list-set-3-deleting-node/ "To delete a node from linked list, we need to do following steps. 1) Find previous node of the node to be deleted. 2) Change the next of previous node. 3) Free memory for the node to be deleted." A special case occurs when you remove the first node. Then, you only need to change the list pointer (or head) to the second node (or do nothing if the list only contains the first node). If you remove the last node, the node that comes before it will now point with its 'next' field to nothing.
25th Jun 2020, 12:51 AM
Itay Kirsh
Itay Kirsh - avatar