How to delete the first node in a Doubly Linked List in Java?

By | July 10, 2020

In his post, We will learn How to Remove/Delete the first node in a Doubly Linked List in Java?

Logic is Very Simple:

  1. if List is Empty than throws NoSuchElementException Exception
  2. if List is not empty then head we will assign to temp Node 
    1. if  head ==  tail that means list has only one Node so nullify tail node
    2. if List has more than one Node then nullify head.next.previous so that first’s node next and next Node’s previous pointer disconnects.

      3.  Afterward, the head’s move to the next pointer and temp’s next pointer nullify.

Below is the complete Source code:

LinkedList.java

 

ClientTest.java

 

The output of this Program:

—–Original LinkedList——-
10 20 30
Removed Element::10
———-After Deleting First Node from Linked List—————
20 30

You May Also Like:
How to represent the Doubly Linked List in Java?
How to insert a node at the beginning of a Doubly Linked List in Java ?
How to insert a node at the end of a Doubly Linked List in Java ?
Representation of Singly Linked List in Java ?
How to insert a node at the beginning of a Singly Linked List in Java?
How to Insert node at the end of a Singly Linked List in Java ?
How to insert a node in Linked List at a given position in Java ?
How to remove the first node from a Singly Linked List in Java ?
How to remove the last node from a Singly Linked List in Java
How to remove a node from a Singly Linked List at a given position in Java?
How to remove a given key from the Singly Linked List in Java ?
How to find the middle node in a Singly Linked List in Java ?
How to search an element in a Singly Linked List in Java ?

That’s all about the How to delete/Remove the first node in a Doubly Linked List in Java?
If you have any feedback or suggestion please feel free to drop in below comment box.

Leave a Reply

Your email address will not be published.