Doubly Linked List Insertion and Deletion in Java

Java Program for Insertion and Deletion in Doubly Linked List

Lets have a look on the code for Doubly Linked List Insertion and Deletion in Java. We will look at different methods available to do so and both deletion and insertion at various positions possible.

java

Doubly Linked List Introduction

Just like a singly linked list in Java, a doubly-linked list is also a non-contiguous data structure.

Which is basically a chain of nodes connected to one another.

Each node has the following –

  • Data
  • Next Node reference
  • Previous Node reference
  • Head reference

The head reference basically denotes the first node(start) of the doubly linked list.

Some versions also contain something called as tail reference which denotes the last node in the doubly linked list.

Doubly Linked List in Java

Possible positions to insert or delete

We can insert or delete at the following positions in the doubly linked list –

  • At start
  • At end
  • In the middle (After a position)

Below are programs for all positions insertion/deletion in Java.

Doubly Linked List in Java an example

Structure of a Node in Doubly Linked List Java

Below is how a node is initialized in Java for a Doubly Linked List –

// Node Class
class Node{
    int data;
    Node next, prev;

    Node(int x) // parameterized constructor
    {
        data = x;
        next = null; 
prev = null;
} }

Doubly Linked List Insertion in Java

Let us look at the program below –

Doubly Linked List Deletion in Java

Let us look at the program below –

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription

Doubly Linked List

  • Introduction to Doubly Linked list in Data Structure
    Click Here
  • Doubly Linked List in –
    C | C++ | Java
  • Insertion in doubly linked list –
    C | C++ | Java
  • Insertion at beginning in doubly linked list –
    C | C++ | Java
  • Insertion at end in doubly linked list –
    C | C++ | Java
  • Insertion at nth node in doubly linked list –
    C | C++ | Java
  • Deletion in doubly linked list  –
    C | C++ | Java
  • Deletion from beginning in doubly linked list :
  • Deletion from nth in doubly linked list :
    C | C++ | Java
  • Deletion from end in doubly linked list :
    C | C++ | Java
  • Insertion and Deletion in a  doubly linked list :
    C | C++ | Java
  • Insertion in the middle in a  doubly linked list :
    C | C++ | Java

Doubly Linked List