# Introduction to Doubly Linked List – Data Structure and Algorithm Tutorials

• Last Updated : 30 Mar, 2023

## What is Doubly Linked List?

A doubly linked list (DLL) is a special type of linked list in which each node contains a pointer to the previous node as well as the next node of the linked list.

Given below is a representation of a DLL node:

## C++

```// Node of a doubly linked list
class Node {
public:
int data;

// Pointer to next node in DLL
Node* next;

// Pointer to previous node in DLL
Node* prev;
};```

## C

```// Node of a doubly linked list

struct Node {
int data;

// Pointer to next node in DLL
struct Node* next;

// Pointer to previous node in DLL
struct Node* prev;
};```

## Java

```// Class for Doubly Linked List

public class DLL {

class Node {
int data;
Node prev;
Node next;

// Constructor to create a new node
// next and prev is by default initialized as null
Node(int d) { data = d; }
}
}```

## Python3

```# Node of a doubly linked list

class Node:
def __init__(self, next=None, prev=None, data=None):

# reference to next node in DLL
self.next = next

# reference to previous node in DLL
self.prev = prev
self.data = data```

## C#

```// Class for Doubly Linked List

public class DLL {

public class Node {
public int data;
public Node prev;
public Node next;

// Constructor to create a new node
// next and prev is by default initialized as null
Node(int d) { data = d; }
}
}
```

## Javascript

```<script>
// Class for Doubly Linked List

/* Doubly Linked list Node */
class Node {
// Constructor to create a new node
// next and prev is by default initialized as null
constructor(val) {
this.data = val;
this.prev = null;
this.next = null;
}
}

</script>```

• A DLL can be traversed in both forward and backward directions.
• The delete operation in DLL is more efficient if a pointer to the node to be deleted is given.
• We can quickly insert a new node before a given node.
• In a singly linked list, to delete a node, a pointer to the previous node is needed. To get this previous node, sometimes the list is traversed. In DLL, we can get the previous node using the previous pointer.

• Every node of DLL Requires extra space for a previous pointer. It is possible to implement DLL with a single pointer though (See this and this).
• All operations require an extra pointer previous to be maintained. For example, in insertion, we need to modify previous pointers together with the next pointers. For example in the following functions for insertions at different positions, we need 1 or 2 extra steps to set the previous pointer.

## Applications of Doubly Linked List:

• It is used by web browsers for backward and forward navigation of web pages
• LRU ( Least Recently Used ) / MRU ( Most Recently Used ) Cache are constructed using Doubly Linked Lists.
• Used by various applications to maintain undo and redo functionalities.
• In Operating Systems, a doubly linked list is maintained by thread scheduler to keep track of processes that are being executed at that time.

Topics:

Introduction:

Basic Operations: