Managing pointers in a doubly linked list in a nutshell
crayoncode

crayoncode @crayoncode

About: Software Architect and Security Officer with 20 years of experience, Web Dev has shifted from my main profession to a hobby as I rarely get to code by now and just love the craft. Check out my channel

Joined:
Oct 25, 2020

Managing pointers in a doubly linked list in a nutshell

Publish Date: Nov 22 '20
8 0

How to code a doubly linked list

Implementing a doubly linked list is all about consistently managing the internal structure of each item's next and previous pointers. At the end it's a set of basic operations that are actually quite easy. Watch this episode of crayoncode and let's write some code together! ⌨️📐⚙️

In Short

A doubly linked list is a least where each item knows its previous and next item.The first item of the list is called head and the last item of the list is called tail.

Structure of a double linked list.

When adding new data to the end of the list, the current tail needs to point to the new item and the new item needs to point to the current tail. After that is being set up, the new item can become the new tail.

Adding an item to a doubly linked list

When removing data from an arbitrary position of the list, the points before and after the item being removed need to be rewired. Which means that the previous item's next pointer will be setup to skip the item to be removed and point to the next-next item. Analogously the next item's previous pointer will be setup to also skip the item to be removed and point to the previous-previous item.

Removing an item from a doubly linked list

Comments 0 total

    Add comment