How to find Nth node from the end of a Singly Linked List in Java?

By | June 18, 2020

In This Post, We will learn How to find Nth node from the end of a Singly Linked List in Java?

Complete Source code :

Program Logic is Very Simple:

  1. We defined two Node references/Pointers(mainPointer & refPointer) and both will be initialized to the head node.
  2. First iterate refPointer to N nodes.
  3. Then iterate both node pointers (mainPointer & refPointer) one step at a time, till refPointer node is null.
  4. Once Setp-3 is completed, the mainPointer represents the Nth node from the end node

Output of this Program:

Linked List is:
10 20 30 40 50 60
3rd Node from end of the List is :40 

 You May Also Like:

That’s all about the How to find Nth node from the end of a Singly 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.