Doubly Linked List
Doubly Linked List is a type of linked list where each node has three parts: data, next pointer and previous pointer. The data part stores the information, the next pointer points to the next node of the linked list and the previous pointer points to the previous node of the linked list. The next pointer of the last node and the previous pointer of the first node stores null. Traversal of items can be done in the forward direction as well as backward direction due to the linking of every node to its next node as well as the previous node.
Node Definition of Doubly Linked List:
/* Node of a doubly linked list */
class Node {
public:
int data;
Node* next; // Pointer to next node in DLL
Node* prev; // Pointer to previous node in DLL
};
/* Node of a doubly linked list */
struct Node {
int data;
struct Node* next; // Pointer to next node in DLL
struct Node* prev; // Pointer to previous node in DLL
};
// Class for Doubly Linked List
public class DLL {
Node head; // head of list
/* Doubly Linked list Node*/
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; }
}
}
# Node of a doubly linked list
class Node:
def __init__(self, next=None, prev=None, data=None):
self.next = next # reference to next node in DLL
self.prev = prev # reference to previous node in DLL
self.data = data
// Class for Doubly Linked List
public class DLL {
Node head; // head of list
/* Doubly Linked list Node*/
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; }
}
}
<script>
// Class for Doubly Linked List
var head; // head of 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>
Operations on Doubly Linked List:
In a doubly linked list, we perform the following operations…
- Insertion: The insertion operation can be performed in three ways as follows:
- Deletion: The deletion operation can be performed in three ways as follows…
- Deleting from the Beginning of the list
- Deleting from the End of the list
- Deleting a Specific Node
- Display: This process displays the elements of a double-linked list.
Introduction to Linked List – Data Structure and Algorithm Tutorials
Linked List is basically chains of nodes where each node contains information such as data and a pointer to the next node in the chain. It is a popular data structure with a wide range of real-world applications. In this article, we will provide a complete introduction of Linked List, which will help you tackle any problem based on Linked List.
Table of Content
- What is a Linked List?
- Basic Terminologies of Linked List
- Importance of Linked List
- Types of Linked List
- Singly Linked List
- Doubly Linked List
- Circular Linked List
- Implementation of Linked List
- Linked List vs. Array
- Advantages of Linked List
- Disadvantages of Linked List
- Applications of Linked List
- Frequently Asked Questions (FAQs) about Linked list
Contact Us