Java program to create and display a doubly linked list17 Mar 2025 | 4 min read In this program, we will create a doubly linked list and print all the nodes present in the list. Doubly Linked List: Doubly Linked List is a variation of the linked list. The linked list is a linear data structure which can be described as the collection of nodes. Nodes are connected through pointers. Each node contains two fields: data and pointer to the next field. The first node of the linked list is called the head, and the last node of the list is called the tail of the list. One of the limitations of the singly linked list is that it can be traversed in only one direction that is forward. The doubly linked list has overcome this limitation by providing an additional pointer that points to the previous node. With the help of the previous pointer, the doubly linked list can be traversed in a backward direction thus making insertion and deletion operation easier to perform. So, a typical node in the doubly linked list consists of three fields: Data represents the data value stored in the node. Previous represents a pointer that points to the previous node. Next represents a pointer that points to next node in the list. ![]() Above picture represents a doubly linked list in which each node has two pointers to point to previous and next node respectively. Here, node 1 represents the head of the list. The previous pointer of the head node will always point to NULL. Next pointer of node one will point to node 2. Node 5 represents the tail of the list whose previous pointer will point to node 4, and next will point to NULL.. Algorithm
a. display() will show all the nodes present in the list.
Program:Output: Nodes of doubly linked list: 1 2 3 4 5 Next TopicJava Programs |
A number is prime if it is divisible by 1 and itself. In other words, a prime number is a natural number with exactly two distinct natural number divisors 1 and itself. For example, 2, 3, 5, 7, 11, etc. are the prime numbers. Note that...
5 min read
In this program, we need to display the upper triangular matrix. Upper Triangular Matrix Upper triangular matrix is a square matrix in which all the elements below the principle diagonal are zero. To find the upper triangular matrix, a matrix needs to be a square matrix that...
4 min read
In this program, we need to find the duplicate characters in the string. Great responsibility To find the duplicate character from the string, we count the occurrence of each character in the string. If count is greater than 1, it implies that a character has a duplicate...
3 min read
In this program, we will create a singly linked list and delete a node from the beginning of the list. To accomplish this task, we need to make the head pointer pointing to the immediate of the initial node which will now become the...
6 min read
In this program, we need to calculate the sum of all the elements of an array. This can be solved by looping through the array and add the value of the element in each iteration to variable sum. Sum of all elements of an array is...
2 min read
? In Java programming, we often required to generate random numbers while we develop applications. Many applications have the feature to generate numbers randomly, such as to verify the user many applications use the OTP. The best example of random numbers is dice. Because when we throw...
7 min read
Java program to print the following pattern on the console 0 909 89098 7890987 678909876 56789098765 4567890987654 345678909876543 23456789098765432 1234567890987654321 Algorithm: STEP 1: START STEP 2: SET lines=10 SET i=1 STEP 3: REPEAT STEP 4 to 15 UNTIL i<=lines STEP 4: SET count =0 SET j=1 STEP 5: REPEAT...
2 min read
It is a problem frequently asked in interviews of top IT companies like Google, Amazon, TCS, and Accenture, etc. By solving the problem, one wants to check the logical ability, critical thinking, and problem-solving skill of the interviewee. So, in this section, we are going to...
4 min read
In this program, we need to find the frequency of each character present in the word. Picture perfect To accomplish this task, we will maintain an array called freq with same size of the length of the string. Freq will be used to maintain the count of...
3 min read
Program to print smallest and biggest possible palindrome word in a given string In this program, we need to find the smallest and biggest palindromic word present in the given string. Wow you own kayak In above example, wow represent the smallest palindrome and kayak represent the biggest...
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