Note - The code examples used in this post are located at my GitHub account - Doubly Linked Lists
In the past couple of posts we've covered the process of searching and inserting items into a doubly linked list. This post will cover the last of the three basic operations on doubly linked lists, deletion.
Since there is no way to directly access items in a doubly linked list like we can with an array, deleting an item involves the following steps.
In the past couple of posts we've covered the process of searching and inserting items into a doubly linked list. This post will cover the last of the three basic operations on doubly linked lists, deletion.
Since there is no way to directly access items in a doubly linked list like we can with an array, deleting an item involves the following steps.
- Search through the list to find the node we want to remove (if it exists).
- Connect the predecessor of the found node to the next of found node.
Step 2 is important as if we do not complete this step then we would have two separate lists since we would have removed the connecting node.