Doubly Linked List Implementation in C++

What is a doubly-linked list?

Shaila Nasrin
Learn Coding Concepts with Shaila

--

First of all, if you don’t know what linked list is, read my blog post about it. Now, the difference between a singly linked list and a doubly-linked list is- in a doubly-linked list every node points to two other nodes (i.e node after it and node before it).

Doubly Linked List

In case of a doubly-linked list, there is a head and there is a tail. Head is the beginning of the linked list and tail is the end of the linked list. As you can see, both of these nodes have two pointers. The head has a next pointer that points to the next node(which is 13 in this case) and a previous pointer that points to NULL. Similarly tail has a previous pointer that points to the previous node(i.e. 13) and a next pointer that points to NULL.

Implementation

As the linked list is a collection of nodes, the first thing we have to do is- make node class which will contain the next pointer, previous pointer, head, tail, and value. This class will also contain a few methods that we have to know in order to work with a doubly-linked list.

--

--