Check Whether the given LinkedList length is even or odd ?

By | July 12, 2020

In this post, We will learn How to write a java program to Check Whether the given LinkedList length is even or odd?

Logic Used In Blow Source Code:

We have to use a 2X pointer means to take a pointer that moves two nodes at a time, in the end, if the length is even then the pointer will be null otherwise it will point to the last node. 

Node.java

 

LinkedList.java

 

ClientTest.java

Output Of this Program:

Displaying LinkedList:
10 20 30 50 60 70
LinkedList Length is Even

Time Complexity: O[n/2] and Space Complexity: O(1) to hold boolean value(isOddLength)

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 Check Whether the given LinkedList length is even or odd?
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 *