How will you print a LinkedList from the End ?

By | July 12, 2020

In this post, We will learn How will you print a LinkedList from the End?

Logic Used In Blow Source Code:

We have to traverse recursively till the end of the LinkedList and While coming back, Start printing every element. That’s Yet.

Below Source code shown output as below:

Display LinkedList from Start to End:::
10 20 30 50 60 70
Display LinkedList from End to Start:::
70 60 50 30 20 10

From the above output, it is clear that When we print LinkedList from End to Start then output is the exact reverse of when we print LinkedList from Start to End.

Complete Source is given Below:

Node.Java

 

LinkedList.java

 

ClientTest.java

Output Of this Program:

Display LinkedList from Start to End:::
10 20 30 50 60 70
Display LinkedList from End to Start:::
70 60 50 30 20 10

Time Complexity: O(n) and Space Complexity: O(n) for method Stack

You May Also Like:

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 ?
How to find the length of a Singly Linked List in Java?
Implementation to reverse a Singly Linked List in Java ?
How to check if LinkedList is palindrome or not in java ?
How to convert sorted Linked List to balanced Binary Search Tree?
How to find the intersection of two LinkedList in java
How to find Nth node from the end of a Singly Linked List in Java?

That’s all about the How will you print a LinkedList from the End?
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. Required fields are marked *