Java program to determine whether a singly linked list is the palindrome17 Mar 2025 | 4 min read In this program, we need to check whether given singly linked list is a palindrome or not. A palindromic list is the one which is equivalent to the reverse of itself. ![]() The list given in the above figure is a palindrome since it is equivalent to its reverse list, i.e., 1, 2, 3, 2, 1. To check whether a list is a palindrome, we traverse the list and check if any element from the starting half doesn't match with any element from the ending half, then we set the variable flag to false and break the loop. In the last, if the flag is false, then the list is palindrome otherwise not. The algorithm to check whether a list is a palindrome or not is given below: Algorithm
a. reverseList() will reverse the order of the node present in the list:
a. isPalindrome() will check whether given list is palindrome or not:
a. display() will display the nodes present in the list:
Program:Output: Nodes of singly linked list: 1 2 3 2 1 Given singly linked list is a palindrome Next TopicJava Programs |
Java program to print the following pattern *000*000* 0*00*00*0 00*0*0*00 000***000 Algorithm: STEP 1: START STEP 2: SET lines=4 STEP 3: Define i, j STEP 4: SET i =1 STEP 5: REPEAT STEP 6 to 15 UNTIL i <= lines STEP 6: SET j=1 STEP 7: REPET STEP 8 and 9 UNTIL j <= lines STEP 8: IF...
2 min read
In this section, we will learn what is a strontio number and also create Java programs to check if the given number is strontio. The strontio number program frequently asked in Java coding tests and academics. Strontio Number Strontio numbers are those four digits numbers when multiplied by...
3 min read
Write a code to prove that strings are immutable in java? Following program demonstrate it. File: ProveStringImmutable .java public class ProveStringImmutable { public static void referenceCheck(Object x, Object y) { if (x == y) { System.out.println("Both pointing to the same reference"); } else { System.out.println("Both are pointing to different reference"); } } public static void...
1 min read
Buzz number is another special number in Java that ends with digit 7 or divisible by 7. Unlike Prime and Armstrong numbers, the Buzz number is not so popular and asked by the interviewers. In simple words, a number is said to be Buzz if it ends...
3 min read
Palindromes are fascinating linguistic constructs that have intrigued minds for centuries. In simple terms, a palindrome is a word, phrase, number, or other sequences of characters that reads the same forward and backward. In the realm of programming, creating a program to determine whether a...
9 min read
In this program, we need to convert the given binary tree to corresponding doubly liked list. The binary tree is a tree data structure in which each node has at most two children node. This can be achieved by traversing the tree in the in-order manner that...
6 min read
In this program, we create a circular linked list and insert a new node in the middle of the list. If the list is empty, both head and tail will point to new node. If the list is not empty, then we will calculate the...
8 min read
In this program, we create a doubly linked list and insert a new node in the middle of list. If list is empty, both head and tail will point to new node. If list is not empty, then we will calculate the size of the...
8 min read
In Java, to find the square root of a number is very easy if we are using the pre-defined method. Java Math class provides sqrt() method to find the square root of a number. In this section, we will create a Java program to find the...
3 min read
In this program, we need to convert given binary tree to a corresponding binary search tree. A tree is said to be the binary tree if each of the nodes has at most two children. Whereas, the binary search tree is the special case of...
7 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India