Tutorial Playlist
Data Structure Tutorial
OverviewArrays in Data Structures: A Guide With Examples
Lesson - 1All You Need to Know About Two-Dimensional Arrays
Lesson - 2All You Need to Know About a Linked List in a Data Structure
Lesson - 3The Complete Guide to Implement a Singly Linked List
Lesson - 4The Ultimate Guide to Implement a Doubly Linked List
Lesson - 5The Fundamentals for Understanding Circular Linked List
Lesson - 6The Ultimate Guide To Understand The Differences Between Stack And Queue
Lesson - 7Implementing Stacks in Data Structures
Lesson - 8Your One-Stop Solution for Stack Implementation Using Array
Lesson - 9Your One-Stop Solution for Queue Implementation Using Array
Lesson - 10Your One-Stop Solution to Learn Depth-First Search[DFS] Algorithm From Scratch
Lesson - 11Your One-Stop Solution for Stack Implementation Using Linked-List
Lesson - 12The Definitive Guide to Understand Stack vs Heap Memory Allocation
Lesson - 13All You Need to Know About Linear Search Algorithm
Lesson - 14All You Need to Know About Breadth-First Search Algorithm
Lesson - 15A One-Stop Solution for Using Binary Search Trees in Data Structure
Lesson - 16The Best Tutorial to Understand Trees in Data Structure
Lesson - 17A Complete Guide to Implement Binary Tree in Data Structure
Lesson - 18A Holistic Look at Using AVL Trees in Data Structures
Lesson - 19All You Need to Know About Tree Traversal in Data Structure
Lesson - 20The Best Guide Youll Ever Need to Understand B-Tree in Data Structure
Lesson - 21The Best Guide You'll Ever Need to Understand Spanning Tree in Data Structure
Lesson - 22The Best and Easiest Way to Understand an Algorithm
Lesson - 23Your One-Stop Solution to Understand Shell Sort Algorithm
Lesson - 24Your One-Stop Solution to Quick Sort Algorithm
Lesson - 25The Most Useful Guide to Learn Selection Sort Algorithm
Lesson - 26Everything You Need to Know About Radix Sort Algorithm
Lesson - 27Everything You Need to Know About the Counting Sort Algorithm
Lesson - 28Everything You Need to Know About the Merge Sort Algorithm
Lesson - 29Insertion Sort Algorithm: One-Stop Solution That Will Help You Understand Insertion Sort
Lesson - 30Everything You Need to Know About the Bubble Sort Algorithm
Lesson - 31The Best Guide Youll Ever Need to Understand Bucket Sort Algorithm
Lesson - 32Your One-Stop Solution to Understand Recursive Algorithm in Programming
Lesson - 33The Definitive Guide to Understanding Greedy Algorithm
Lesson - 34Your One-Stop Solution to Understand Backtracking Algorithm
Lesson - 35The Fundamentals of the Bellman-Ford Algorithm
Lesson - 36Your One-Stop Solution for Graphs in Data Structures
Lesson - 37The Best Guide to Understand and Implement Solutions for Tower of Hanoi Puzzle
Lesson - 38A Simplified and Complete Guide to Learn Space and Time Complexity
Lesson - 39All You Need to Know About the Knapsack Problem : Your Complete Guide
Lesson - 40The Fibonacci Series: Mathematical and Programming Interpretation
Lesson - 41The Holistic Look at Longest Common Subsequence Problem
Lesson - 42The Best Article to Understand What Is Dynamic Programming
Lesson - 43A Guide to Implement Longest Increasing Subsequence Using Dynamic Programming
Lesson - 44A Holistic Guide to Learn Stop Solution Using Dynamic Programming
Lesson - 45One Stop Solution to All the Dynamic Programming Problems
Lesson - 46Understanding the Fundamentals of Binomial Distribution
Lesson - 47Heres All You Need to Know About Minimum Spanning Tree in Data Structures
Lesson - 48Understanding the Difference Between Array and Linked List
Lesson - 49The Best Article Out There to Understand the B+ Tree in Data Structure
Lesson - 50A Comprehensive Look at Queue in Data Structure
Lesson - 51Your One-Stop Solution to Understand Coin Change Problem
Lesson - 52The Best Way to Understand the Matrix Chain Multiplication Problem
Lesson - 53Your One-Stop Solution to Learn Floyd-Warshall Algorithm for Using Dynamic Programming
Lesson - 54Doubly Linked List: A Complete Implementation Guide
Lesson 5 of 54By Simplilearn
Last updated on Sep 18, 20212866- Tutorial Playlist
Data Structure Tutorial
OverviewArrays in Data Structures: A Guide With Examples
Lesson - 1All You Need to Know About Two-Dimensional Arrays
Lesson - 2All You Need to Know About a Linked List in a Data Structure
Lesson - 3The Complete Guide to Implement a Singly Linked List
Lesson - 4The Ultimate Guide to Implement a Doubly Linked List
Lesson - 5The Fundamentals for Understanding Circular Linked List
Lesson - 6The Ultimate Guide To Understand The Differences Between Stack And Queue
Lesson - 7Implementing Stacks in Data Structures
Lesson - 8Your One-Stop Solution for Stack Implementation Using Array
Lesson - 9Your One-Stop Solution for Queue Implementation Using Array
Lesson - 10Your One-Stop Solution to Learn Depth-First Search[DFS] Algorithm From Scratch
Lesson - 11Your One-Stop Solution for Stack Implementation Using Linked-List
Lesson - 12The Definitive Guide to Understand Stack vs Heap Memory Allocation
Lesson - 13All You Need to Know About Linear Search Algorithm
Lesson - 14All You Need to Know About Breadth-First Search Algorithm
Lesson - 15A One-Stop Solution for Using Binary Search Trees in Data Structure
Lesson - 16The Best Tutorial to Understand Trees in Data Structure
Lesson - 17A Complete Guide to Implement Binary Tree in Data Structure
Lesson - 18A Holistic Look at Using AVL Trees in Data Structures
Lesson - 19All You Need to Know About Tree Traversal in Data Structure
Lesson - 20The Best Guide Youll Ever Need to Understand B-Tree in Data Structure
Lesson - 21The Best Guide You'll Ever Need to Understand Spanning Tree in Data Structure
Lesson - 22The Best and Easiest Way to Understand an Algorithm
Lesson - 23Your One-Stop Solution to Understand Shell Sort Algorithm
Lesson - 24Your One-Stop Solution to Quick Sort Algorithm
Lesson - 25The Most Useful Guide to Learn Selection Sort Algorithm
Lesson - 26Everything You Need to Know About Radix Sort Algorithm
Lesson - 27Everything You Need to Know About the Counting Sort Algorithm
Lesson - 28Everything You Need to Know About the Merge Sort Algorithm
Lesson - 29Insertion Sort Algorithm: One-Stop Solution That Will Help You Understand Insertion Sort
Lesson - 30Everything You Need to Know About the Bubble Sort Algorithm
Lesson - 31The Best Guide Youll Ever Need to Understand Bucket Sort Algorithm
Lesson - 32Your One-Stop Solution to Understand Recursive Algorithm in Programming
Lesson - 33The Definitive Guide to Understanding Greedy Algorithm
Lesson - 34Your One-Stop Solution to Understand Backtracking Algorithm
Lesson - 35The Fundamentals of the Bellman-Ford Algorithm
Lesson - 36Your One-Stop Solution for Graphs in Data Structures
Lesson - 37The Best Guide to Understand and Implement Solutions for Tower of Hanoi Puzzle
Lesson - 38A Simplified and Complete Guide to Learn Space and Time Complexity
Lesson - 39All You Need to Know About the Knapsack Problem : Your Complete Guide
Lesson - 40The Fibonacci Series: Mathematical and Programming Interpretation
Lesson - 41The Holistic Look at Longest Common Subsequence Problem
Lesson - 42The Best Article to Understand What Is Dynamic Programming
Lesson - 43A Guide to Implement Longest Increasing Subsequence Using Dynamic Programming
Lesson - 44A Holistic Guide to Learn Stop Solution Using Dynamic Programming
Lesson - 45One Stop Solution to All the Dynamic Programming Problems
Lesson - 46Understanding the Fundamentals of Binomial Distribution
Lesson - 47Heres All You Need to Know About Minimum Spanning Tree in Data Structures
Lesson - 48Understanding the Difference Between Array and Linked List
Lesson - 49The Best Article Out There to Understand the B+ Tree in Data Structure
Lesson - 50A Comprehensive Look at Queue in Data Structure
Lesson - 51Your One-Stop Solution to Understand Coin Change Problem
Lesson - 52The Best Way to Understand the Matrix Chain Multiplication Problem
Lesson - 53Your One-Stop Solution to Learn Floyd-Warshall Algorithm for Using Dynamic Programming
Lesson - 54
Table of Contents
View MoreA Doubly linked list is used in navigation systems or to represent a classic deck of cards. A Doubly linked list is a bidirectional linked list; i.e., you can traverse it from head to tail node or tail to head node. Unlike singly-linked lists, its node has an extra pointer that points at the last node.
How Do You Implement a Doubly Linked List?
You create nodes of doubly-linked lists using classes or structures. These nodes are then linked with each other using the next and the previous pointer.
Code:
//A c++ program to implement linked list
#include
using namespace std;
/* A class to create node */
class Node
{
public:
int data;
Node *next;
Node *prev;
};
//A function to insert at the
//beginning of the list
void push[Node** head, int newdata]
{
//create new node
Node* newnode = new Node[];
/* put in the data */
newnode->data = newdata;
/* As we are adding at the beginning,
prev is always NULL */
newnode->prev = NULL;
/* link new node's next to head */
newnode->next = [*head];
/* change prev of head node to newnode */
if[[*head] != NULL]
[*head]->prev = newnode ;
/* changing head node */
[*head] = newnode;
}
/* A c++ program to print the list */
void printlist[Node *head]
{
while[head != NULL]
{
cout data next;
}
}
int main[]
{
/* We will start with an empty list */
Node* head = NULL;
/*lets create a linked list: 2->3->5->7 */
push[&head, 7];
push[&head, 5];
push[&head, 3];
push[&head, 2];
cout prev = NULL;
/* link the next of newnode to the head */
newnode->next = [*head];
/* change prev of head node to newnode */
if[[*head] != NULL]
[*head]->prev = newnode ;
/* changing head */
[*head] = newnode;
}
/* A c++ program to traverse the linked list */
void traverse[Node *node]
{
while[node != NULL]
{
cout data next;
}
}
/* Function to reverse traverse a Linked List */
void revtraverse[Node **head]
{
Node* tail = *head;
// Traversing till tail of the linked list
while [tail->next != NULL] {
tail = tail->next;
}
// Traversing linked list from tail
// and printing the node->data
while [tail != *head] {
cout data prev;
}
cout data 3->5->7 */
push[&head, 7];
push[&head, 5];
push[&head, 3];
push[&head, 2];
cout prev = newnode;
/* changing head */
[*head] = newnode;
}
/* A function to insert a node after a given node */
void insertAfter[Node* prevnode, int newdata]
{
/*1. check if the given prevnode is NULL */
if [prevnode == NULL]
{
coutnext = prevnode->next;
/* 5. Make the prevnode's next as newnode */
prevnode->next = newnode;
/* 6. Make prevnode as newnode's prev */
newnode->prev = prevnode;
/* 7. Change previous of newnode's next node */
if [newnode->next != NULL]
newnode->next->prev = newnode;
}
/* A function to insert at the end of the list */
void append[Node** head, int newdata]
{
/* create newnode */
Node* newnode = new Node[];
Node* last = *head;
/* put in the data */
newnode->data = newdata;
/*This newnode is going to be the last node, so
we will make next of it as NULL*/
newnode->next = NULL;
/* check if the Linked List is empty, then make the new
node as head */
if [*head == NULL]
{
newnode->prev = NULL;
*head = newnode;
return;
}
/* Else traverse till the last node */
while [last->next != NULL]
last = last->next;
/* Change the next of last node */
last->next = newnode;
/* Make last node as new node's prev */
newnode->prev = last;
return;
}
// A function to print the list
void printList[Node* node]
{
while [node != NULL]
{
cout7->6->NULL
// Insert 4 at the end
append[&head, 4]; //1->7->6->4->NULL
// Insert 8, after 7
insertAfter[head->next, 8]; //1->7->8->6->4->NULL
cout next;
/* Change next only if node to be
deleted is NOT the last node */
if [del->next != NULL]
del->next->prev = del->prev;
/* Change prev only if node to be
deleted is NOT the first node */
if [del->prev != NULL]
del->prev->next = del->next;
/* Finally, free the memory occupied by del*/
free[del];
return;
}
/* A function to insert a node at the beginning of the list*/
void push[Node** head, int newdata]
{
/* create newnode */
Node* newnode = new Node[];
/* put in the data */
newnode->data = newdata;
/* link the new node's next to head
and previous as NULL */
newnode->next = [*head];
newnode->prev = NULL;
/* link the head node's prev to new node */
if [[*head] != NULL]
[*head]->prev = newnode;
/* changing head */
[*head] = newnode;
}
/* Function to print nodes in a given linked list
This function is the same as printList[] of singly linked list */
void printList[Node* node]
{
while [node != NULL]
{
cout data next;
}
}
int main[]
{
/* Start with the empty list */
Node* head = NULL;
/* Let us create the linked list 2357 */
push[&head, 7];
push[&head, 5];
push[&head, 3];
push[&head, 2];
cout next]; /*delete middle node*/
deleteNode[&head, head->next]; /*delete last node*/
/* Modified linked list will be NULLNULL */
cout