Java program to create a doubly linked list of n nodes and display it in reverse order17 Mar 2025 | 3 min read In this program, we create a doubly linked list, and then reverse the list by reversing the direction of the list and print out the nodes. ![]() Traverse through the list by swapping the previous pointer with next pointer of each node. Then, swap the position of head and tail node that is, head of the original list will become tail of new list and tail of the original list will become head of the new list. So, the reversed list will be: ![]() Algorithm
a. reverse() will reverse the given doubly linked list.
a. display() will show all the nodes present in the list.
Program:Output: Original List: 1 2 3 4 5 Reversed List: 5 4 3 2 1 Next TopicJava Programs |
In this section, we will learn what is an autobiographical number and also create Java programs to check if the given number is autobiographical or not. The autobiographical number program frequently asked in Java coding tests to check the logic of the programmer. Autobiographical Number A digit count...
4 min read
Java Convert Binary to Decimal We can convert binary to decimal in java using Integer.parseInt() method or custom logic. Java Binary to Decimal conversion: Integer.parseInt() The Integer.parseInt() method converts string to int with given redix. The signature of parseInt() method is given below: public static int parseInt(String s,int redix) Let's see...
2 min read
Write a code to check whether one string is a rotation of another? File: RotationString .java public class RotationString { public static boolean checkRotation(String st1, String st2) { if (st1.length() != st2.length()) { return false; } String st3 = st1 + st1; if (st3.contains(st2)) return true; else return false; } public static void main(String[] args) { String str1...
1 min read
Java program to print the following pattern on the console Algorithm: STEP 1: START STEP 2: DEFINE i, j STEP 3: SET n=6 STEP 4: SET i=n. REPEAT STEP 5 to STEP 7 UNTIL i>0. STEP 5: SET j=0. REPEAT STEP 6 UNTIL j STEP 6: PRINT * and SET j=j+1 STEP...
2 min read
In this program, we need to find the transpose of the given matrix and print the resulting matrix. Transpose of Matrix Transpose of a matrix can be found by interchanging rows with the column that is, rows of the original matrix will become columns of the new...
4 min read
In this program, we will create a circular linked list and delete a node from the middle of the list. If the list is empty, display the message "List is empty". If the list is not empty, we will calculate the size of the list...
9 min read
Java Program to find Second Smallest Number in an Array We can find the second smallest number in an array in java by sorting the array and returning the 2nd element. Let's see the full example to find the second smallest number in java array. public class SecondSmallestInArrayExample{ public...
2 min read
In a Jail, a corridor is provided. The length of the corridor is L units. An array lightArr[] is given, which is also of the size L. The lightArr[] contains only to values 0 & 1. At each unit of the corridor a light is given....
14 min read
Java program to print the following pattern on the console Algorithm: STEP 1: START STEP 2: SET size=6. STEP 3: SET i=size. REEPAT STEP 4 to STEP 9 UNTIL i!=0 STEP 4: SET j=0.REPEAT STEP 5 UNTIL j<(size-i). STEP 5: PRINT "" and SET j=j+1 STEP 6: SET k = 0. REPEAT...
2 min read
In Java, there are many ways to swap two numbers. Generally, we use either swap() method of the Math class or use a third (temporary) variable to swap two numbers. Except these two ways, we can also swap two numbers using the bitwise operator (XOR) and...
3 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