August 2020
Intermediate to advanced
508 pages
11h 53m
English
Linked lists shine when it comes to deletion as well, especially when deleting from the beginning of the list.
To delete a node from the beginning of a linked list, all we need to do is perform one step: we change the first_node of the linked list to now point to the second node.
Let’s return to our example of the linked list containing the values "once", "upon", "a", and "time". If we want to delete the value "once", we could simply change the linked list to begin at "upon":
| | list.first_node = node_2 |
Contrast this with an array in which deleting the first element means shifting all remaining data one cell to the left, which takes O(N) time.
When it comes to deleting the final node of a linked list, the actual deletion takes one step—we ...
Read now
Unlock full access