How to insert a node at the end of a Doubly Linked List in Java ?

By | July 9, 2020

In Previous Post, How to insert a node at the beginning of a Doubly Linked List in Java ? we learned how to insert a Node at the beginning of a Doubly LinkedList.

In this post, we will learn How to insert a node at the end of a Doubly Linked List in Java?

Doubly Linked List

Logic is very simple:

If the head is null that means LinkedList is empty so make newNode as head Node else newNode assign to tail’s next and assign tail to newNode’s previous, finally assign newNode to tail.

Below is the complete Source code:

LinkedList.java

 

ClientTest.java

The output of this Program:

—–Print Linked List in Forward Direction——-
10 20 30
—–Print Linked List in Backward Direction——-
30 20 10

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 ?
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 insert a node at the end of 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.